Saving data to DB from custom controls

taenkarth

New member
Joined
May 2, 2006
Messages
3
Programming Experience
1-3
Hi there.

I am currently writing a very small app that is storing its data in an Access 2003 DB. I had about 10 tables and some various linking (not that this matters but wanted to let you know how small it is)

I had finally gotten used to databinding in VS 2003, well for the most part, and now I find myself lost in the Dataset, DataBinder, DataAdapter, DataTableAdapter, DataTable, etc etc...

I have created a Winform with controls that are not databound and I ahve a submit(Add) button at the bottom that when pushed I would like for it to insert the data into my DB.

The problem is that when I try to update I am not sure what I am supposed to update! Should I run the .Update method of my table adapter? should I tell my dataset to acceptchanges? Here is some code I ahve tried below...please notice the commented lines and comment back on them...I am just missing the full picture of how they al coincide i think...

VB.NET:
[SIZE=2][COLOR=#0000ff]
Dim[/COLOR][/SIZE][SIZE=2] taCustomer [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] AssetsDataSetTableAdapters.CustomerTableAdapter
taCustomer.Insert(CID, Name, Addr1, Addr2, City, State, Zip, Phone1, Phone2, Fax, Web, status, Contact, Email)
[/SIZE][SIZE=2][COLOR=#008000]'Me.CustomerTableAdapter.Update(AssetsDataSet.Customer)
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Validate()
[/SIZE][SIZE=2][COLOR=#008000]'Me.BindingSource1.EndEdit()
[/COLOR][/SIZE][SIZE=2]taCustomer.Update([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].AssetsDataSet1.Customer)
MsgBox([/SIZE][SIZE=2][COLOR=#800000]"Update successful"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
MsgBox([/SIZE][SIZE=2][COLOR=#800000]"Update failed"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE]

Thanks in advance!
 
Back
Top