Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update DB through Dataset...

Status
Not open for further replies.

Vandy02

Programmer
Jan 7, 2003
151
0
0
US
I have a dataset that I populate from a DB and then modify the local data. How do I take these changes back to the database?

refere to pull data sub() for data loading...

this the update I tried
=====================================================
Private Sub Update_DB()

oOleDbConnection = New OleDb.OleDbConnection(CONN)
oOleDbConnection.Open()
If ConnectionState.Open Then
TextBox1.Text = "Connection is made to Main"
TextBox1.BackColor = Color.Blue
Else
TextBox1.Text = "Unable to make connection"
TextBox1.BackColor = Color.Red
End If
daDTEmp.Update(now, 0)

END SUB 'Update_DB
=====================================================
i receive:
Additional information: Object reference not set to an instance of an object.


Note, after I make a change to a column in the table a have a button that looks at the particular column to assure that the column was update...so I know I am updating the local data..

=====================================================
pull data sub()
....

strDTEmp = "Select * from EMP"
strDTDept = "Select * from DEPT"

Dim daDTEmp = New OleDb.OleDbDataAdapter(strDTEmp, CONN)
Dim daDTDept = New OleDb.OleDbDataAdapter(strDTDept, CONN)

daDTEmp.Fill(now, "EMP")
daDTDept.Fill(now, "DTDept")

oOleDbConnection.Close()

DTEmp = now.Tables(0) ' set up datatable for dataview

end sub 'pull data
=====================================================

thanks
 
I got this to work so far....but not exactly what I am looking for....is there a way to update the table based on whether something has changed in the dataset...in this way I would only be updating db where i made changes...

Not sure how to do this with the UPDATE statement as I want the changes to go over...

Dim up As String = "Update EMP set ENAME = 'MIKE'"

Dim daDTEmp = New OleDb.OleDbDataAdapter

daDTEmp.UpdateCommand = New OleDbCommand(up, oOleDbConnection)

daDTEmp.Update(now, "EMP")
 
I wouldn't use the command builder supplied with VB.Net I would create a sub that has an insert,update, and delete commands. Check out this post from before that i helped somebody with this same issue thread796-919791. Your dataset will mark any rows that are Modified,Inserted, or Updated. If you are continually working with the dataset i would suggest not saving changes until your done editing records, so that the whole dataset is pushed to the DB all at once which will also allow you to use a rollback if any row fails.

Sincerely,
Fritts
 
Did you check out my post and did it work for you, i think you should at least give some feedback.
Sincerely,
Fritts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top