473,662 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing Database to Text Boxes and automatically update using timer

2 New Member
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.d atabindings.Cle ar() I will get an error because I am will be writing to the same databind twice.

Any Solutions??

thanks
Mar 9 '08 #1
2 1897
dwadish
129 New Member
Please Commend the line this.textBox_no rth.DataBinding s.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(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
Mar 9 '08 #2
CommonElements
2 New Member
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?
Mar 9 '08 #3

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

Similar topics

4
1353
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 or datalist I found plenty of examples of how to do that and can get that to work. I simply want to update my databound text boxes. I'm using visual studios DataAdapters, DataSets and Dataviews. I can insert to the database utilizing the...
1
961
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 "-" labels between them. Now, how can I bind ds.item to these 3 boxes and then when I call da.update to automatically update them. I would like to avoid writing custom da.Update command with all parameters
6
3413
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 example, say I had a table in a DB that contained movie subjects: Horror, Sci-Fi, Comedy etc. Would it be possile for the VB app to look at these and then create the text boxes Horror, Sci-Fi and Comedy? Thanks, BWT
9
4986
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 created three combo boxes that cascade down from Name to Project to Date and when this has been chosen I have four textbox fields I want to display based on this selection. I tried linking the last combo box comboDate to update these fields after...
2
1565
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 VB.net so my question may be very elementary with I need some assistance, so here goes: I am using vb.net 2003. I have a form with four bound text boxes. I am using an ODBC data adapter
5
2021
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 Entry”. I want to create 2 text box to be populated with ContactName, PhoneNumber from that table when a supplier name is selected. How do I do that? Access2000 Vista Thanks, John
2
1506
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 have created a form with this info along with two other text boxes. What I want to be able to do is select an Event using the combo box and then for the two other text boxes (event price, event name) to update automatically according to the event I...
9
2080
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 and I would like to make a data entry form (frmDataEntry) with a two text boxes. The table (tblPeople) has fields Name and Age. Both are character fields. The Form has two text boxes (txtName and txtAge)
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8546
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.