SQL Server 2005, read from/write to it

gonegaming12

Member
Joined
Jul 10, 2007
Messages
5
Programming Experience
3-5
So I have a data base called ServerData. Then the dataset for that is called ServerDataSet. Then on my main form I have a dataset control called Srv_Data and tableadapters & bindingsources to all the tables in ServerData.

So I'm connected to the database but I can't figure out have to read from/write to it. So can somebody explain this to me. Every example I have seen has been how to connect to the database through code, but I have already done that, and I want to use the database.
 
Your form should have:

1/more BindingSource, bound to a 1/more table in ServerDataSet
1/more Controls bound to their relevant BindingSource
1/more TableAdapters

The TableAdapter is like a 2 way tap. The DataSet is like a bucket.

To download something from the ACME database table you do:

acmeTableAdapter.Fill(serverDataSet.ACME)

The ACMEDataTable in the dataset is now full of data (all rows from the database) all bound controls will update to show the content of the first row.
A BindingNavigator may be used to alter the .Position of the BindingSource which will cause bound controls to show new values

You edit some of the values on display, and upon calling ACMEBindingSource.EndEdit() those values will be committed to the dataset. EndEdit() is also implicitly called if you navigate to another record.

To return the data to the database, you are advised to:

Me.Validate() 'make any controls sent the most recent change to the Bindingsource
ACMEBindingSource.EndEdit() 'BS commits into dataset
ACMETableAdapter.Update(serverDataSet.ACME) 'save changes


-

If you are working with a file based database (MDB, MDF), please now read the DNU link in my signature
 
Back
Top