Storing Database to Text Boxes and automatically update using timer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CommonElements
    New Member
    • Mar 2008
    • 2

    Storing Database to Text Boxes and automatically update using timer

    Hi,

    1. I am using Visual Studio.NET 2005 C# Win Form
    2. I have setup a database connection to my Access Database using ADO.NET
    3. On my system timer I have the following code to execute every 1 sec:
    [code=vbnet]
    private void timer1_Tick(obj ect sender, EventArgs e)
    {
    OleDbConnection myConnection = new OleDbConnection (myConnectionSt ring);
    OleDbCommand myCommand = new OleDbCommand("S ELECT *FROM Lights_Settings ", myConnection);
    OleDbDataAdapte r myDataAdapter = new OleDbDataAdapte r(myCommand);

    try
    {
    myConnection.Op en();
    myDataAdapter.F ill(myDataSet, "Lights_Setting s");
    this.textBox_no rth.DataBinding s.Clear();
    this.textBox_no rth.DataBinding s.Add("text", myDataSet, "Lights_Setting s.North" );
    myConnection.Cl ose();

    }
    catch (Exception ex)
    {
    MessageBox.Show ("Error reading database: " + ex.Message);
    myConnection.Cl ose();
    }

    }
    [/code]
    4. The problem: If I change the values in the database table, when the timer ticks over again the text box value is not updated. If I remove the textbox_north.d atabindings.Cle ar() I will get an error because I am will be writing to the same databind twice.

    Any Solutions??

    thanks
  • dwadish
    New Member
    • Nov 2006
    • 129

    #2
    Please Commend the line this.textBox_no rth.DataBinding s.Clear();

    hope it will ok


    Originally posted by CommonElements
    Hi,

    1. I am using Visual Studio.NET 2005 C# Win Form
    2. I have setup a database connection to my Access Database using ADO.NET
    3. On my system timer I have the following code to execute every 1 sec:

    private void timer1_Tick(obj ect sender, EventArgs e)
    {
    OleDbConnection myConnection = new OleDbConnection (myConnectionSt ring);
    OleDbCommand myCommand = new OleDbCommand("S ELECT *FROM Lights_Settings ", myConnection);
    OleDbDataAdapte r myDataAdapter = new OleDbDataAdapte r(myCommand);

    try
    {
    myConnection.Op en();
    myDataAdapter.F ill(myDataSet, "Lights_Setting s");
    this.textBox_no rth.DataBinding s.Clear();
    this.textBox_no rth.DataBinding s.Add("text", myDataSet, "Lights_Setting s.North" );
    myConnection.Cl ose();

    }
    catch (Exception ex)
    {
    MessageBox.Show ("Error reading database: " + ex.Message);
    myConnection.Cl ose();
    }

    }

    4. The problem: If I change the values in the database table, when the timer ticks over again the text box value is not updated. If I remove the textbox_north.d atabindings.Cle ar() I will get an error because I am will be writing to the same databind twice.

    Any Solutions??

    thanks

    Comment

    • CommonElements
      New Member
      • Mar 2008
      • 2

      #3
      Yes I commented out the line this.textBox_No rth.databinding s.clear() and i got the following error message:

      "This causes two bindings in the collection to bind to the same property. Parameter name: binding"

      Im guessing I am getting this error because I am bind the datasource in a timer and it will keep binding the same source over and over again.

      Any solutions?

      Comment

      Working...