How to modify many database fields content easily?

Forum Home Forums Development and Integration How to modify many database fields content easily?

This topic contains 9 replies, has 3 voices, and was last updated by Mikhail Mikhail 2 weeks, 2 days ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1347
    inpelsa
    inpelsa
    Participant

    Hi,

    Some channels got wrong data on a device for up to one hour.

    I wonder if there is any way to update all that data easily instead of going minute row by row and channel to update it.

    “All my data are belong to you!” :_(

    PD: All_your_base_are_belong_to_us

    #1348
    inpelsa
    inpelsa
    Participant

    well… I just saw it was for 4 hours…

    #1349
    Mikhail
    Mikhail
    Moderator

    Hi,
    A simple application is needed to update data because the archive is not SQL database.

    #1368
    inpelsa
    inpelsa
    Participant

    I already fixed data but I’m curious…

    On http://rapidscada.org/integration-with-rapid-scada/ section “First Way. Direct File Access” you talk about loading data:

    
    using Scada.Data;
    ...
    SrezTableLight snapshotTable = new SrezTableLight();
    SrezAdapter adapter = new SrezAdapter();
    adapter.FileName = @"C:\SCADA\ArchiveDAT\Cur\current.dat";
    adapter.Fill(snapshotTable);
    
    foreach (SrezTableLight.Srez snapshot in snapshotTable.SrezList.Values)
    {
        int cnlCnt = snapshot.CnlNums.Length;
        Console.WriteLine("Snapshot {0}, number of channels is {1}:", 
            snapshot.DateTime, cnlCnt);
    
        for (int i = 0; i < cnlCnt; i++)
        {
            Console.WriteLine("    Channel[{0}] = {1}, {2}", snapshot.CnlNums[i],
                snapshot.CnlData[i].Val, snapshot.CnlData[i].Stat);
        }
    }
    

    As I see a .Fill() that would not keep linked adapter and table data objects…

    How can data be modified ?
    I cannot see any update/save method. Is SaveToFile the only way?

    Thanks!

    #1370
    Mikhail
    Mikhail
    Moderator

    You should use srezAdapter.Update(srezTable) method after modify data in srezTable.

    Changing data:
    https://github.com/RapidScada/scada/blob/master/ScadaServer/ScadaServerCtrl/FrmSrezTableEdit.cs#L331

    Saving: https://github.com/RapidScada/scada/blob/master/ScadaServer/ScadaServerCtrl/FrmSrezTableEdit.cs#L103

    “Srez” means a snapshot ))

    #1382
    inpelsa
    inpelsa
    Participant

    To anyone interested…

    bulk data updater

    Taking the source code of Scada server (building /solving references) and doing following modifications you got it!:

    In FrmSrezTableEdit.cs set:
    – datagridview1.multiselect = true
    – Add a label, textbox and command button near the SQL filter
    – Add this code on Update command button:

    
           private void btnUpdate_Click(object sender, EventArgs e)
            {
                Int32 numloops = 0;
    
                foreach (DataGridViewRow row1 in dataGridView1.SelectedRows)
                {
                    dataGridView1.CurrentCell = dataGridView1.Rows[row1.Index].Cells[0];
    
                    foreach (DataGridViewRow row2 in dataGridView2.Rows)
                    {
                        row2.Cells[1].Value = txtNewValue.Text;
                        dataTable2.AcceptChanges();
                    }
    
                    if (numloops % 10 == 0) { Application.DoEvents(); }
                    numloops++;
    
                }
            }
    

    It will allow you to select a datetime range, a channel/value filter and update all data valuees at a time.

    Not nice (even more if I’m not an expert on C#), but will reduce any update task from hours to minutes…

    • This reply was modified 3 years, 3 months ago by inpelsa inpelsa.
    #1385
    Mikhail
    Mikhail
    Moderator

    The great approach! I think it should be included in the SCADA-Server shell.

    #1391
    inpelsa
    inpelsa
    Participant

    Please, feel free to add it yourself with nice code 😉

    Even more, if you add a 2nd textbox for the status value (plus some program logic to modify data only in case a value is written) and a way to select a range of days to modify… it should be more than enough!!!

    #5986
    Avatar
    kejtan
    Participant

    Hi Mikhail,

    I am experiencing a similar problem and need to modify the existing data. I am currently using v5.7.1. Is there any tools available for such manipulation or do I need to do it via the source code method? Thanks!

    #5987
    Mikhail
    Mikhail
    Moderator

    Hi,
    To find the best method, please provide an example what do you need to update.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.