473,320 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. private void timer1_Tick(object sender, EventArgs e)
  2. {
  3. OleDbConnection myConnection = new OleDbConnection(myConnectionString);
  4. OleDbCommand myCommand = new OleDbCommand("SELECT *FROM Lights_Settings", myConnection);
  5. OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myCommand);
  6.  
  7.   try
  8.   {
  9. myConnection.Open(); 
  10. myDataAdapter.Fill(myDataSet, "Lights_Settings"); 
  11. this.textBox_north.DataBindings.Clear();
  12. this.textBox_north.DataBindings.Add("text", myDataSet, "Lights_Settings.North" );
  13.  myConnection.Close();
  14.  
  15. }
  16.             catch (Exception ex)
  17.             {
  18.                 MessageBox.Show("Error reading database: " + ex.Message);
  19.                 myConnection.Close();
  20.             }
  21.  
  22.         }
  23.  
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.databindings.Clear() I will get an error because I am will be writing to the same databind twice.

Any Solutions??

thanks
Mar 9 '08 #1
2 1874
dwadish
129 100+
Please Commend the line this.textBox_north.DataBindings.Clear();

hope it will ok


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(object sender, EventArgs e)
{
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
OleDbCommand myCommand = new OleDbCommand("SELECT *FROM Lights_Settings", myConnection);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myCommand);

try
{
myConnection.Open();
myDataAdapter.Fill(myDataSet, "Lights_Settings");
this.textBox_north.DataBindings.Clear();
this.textBox_north.DataBindings.Add("text", myDataSet, "Lights_Settings.North" );
myConnection.Close();

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

}

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.databindings.Clear() I will get an error because I am will be writing to the same databind twice.

Any Solutions??

thanks
Mar 9 '08 #2
Yes I commented out the line this.textBox_North.databindings.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?
Mar 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: enrique | last post by:
Hi, I apologize for a newbie question, but my books/research have yielded me no examples and my time is now short. I simply want to update data from text boxes (fields). I'm not using a datagrid...
1
by: excelleinc.com | last post by:
Hello, I'm building a windows form that is including SSN #. SSN's are stored as INTEGER in MSDE db and would like to keep it that way. However, I want on my form to be split in 3 text boxes with...
6
by: BurntWithTime | last post by:
Hello everyone, Please can anyone tell me if it is possible for a VB.NET application to check a database and then create textboxes on a form that correspond to those records on the database? For...
9
by: Marianne160 | last post by:
Hi, I know there are various answers to this problem available on the web but none of them seem to work for me. I am using Access 2003 to make a form to look up data from a table. I have so far...
2
by: =?Utf-8?B?TXIgQg==?= | last post by:
I had originally posted this in another thread, but did not get and results. I appologize for cross posting but I really would like to get some assistance with this. I am new to developing in...
5
by: John Torres | last post by:
I have a tblSupplierInformation which consist of SupplierID, ContactName, PhoneNumber among other name fields. I’m creating a combo box from the tblSupplierInformation to a form “Purchase Order...
2
by: kels | last post by:
Hi I've been searching all day on how to do this and I don't know how! I have tblEvents that store details of events that are created and contain info such as location, price and event name I...
9
by: RICHARD BROMBERG | last post by:
Please bear in mind that I am a newbie. I am posting this question a second time because the responses to my earlier post were a little wide of the mark. So, here goes: I am using Access 2000...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.