Updating Source Data in ADO.NET (Continued)

G

Guest

I'm still having trouble getting the updates to work. I read the row in from
the dataset and bind it to a textbox. When the user hits a Save button, I
have code to perform the update, but nothing gets Updated. No errors, just
no update.

Here is the Code I am using to read and Update an Access Table called
CUSTOMERS with 2 columns: CUSTID, and CUSTNAME

First is the code to set up the connections:
Public odbc_conn As String = "PageTimeout=5;DSN=MS Access
Database;DefaultDir=C:\testdb;DriverId=25;DBQ=C:\testdb\Access_MGSDATA.mdb;FIL=MS Access;MaxBufferSize=2048;UID=admin"
Dim daCustomers As Odbc.OdbcDataAdapter
Dim dsCustomers As DataSet
Dim dtCustomers As DataTable
Dim mgscust As New Odbc.OdbcConnection(odbc_conn)
Dim strSQL As String = _
"SELECT * FROM Customers where Custid = '000007' order by
Custid"
Dim ocmd As New Odbc.OdbcCommand(strSQL, mgscust)

Then I have this code in the Form Load event

daCustomers = New Odbc.OdbcDataAdapter(ocmd)
dsCustomers = New DataSet
daCustomers.Fill(dsCustomers, "Customers")
dtCustomers = dsCustomers.Tables(0)

TextBox1.DataBindings.Add("Text", dtCustomers, "Custid")
TextBox2.DataBindings.Add("Text", dtCustomers, "Custname")

Finally When the user hits a Save Button I have thiis code on it's event:

strSQL = "UPDATE Customers SET Custid = '" & TextBox1.Text & "'" & _
",Custname = " & TextBox2.Text & " where Custid
='000007'"
Dim ucmd As New Odbc.OdbcCommand(strSQL, mgscust)

daCustomers.UpdateCommand() = ucmd
daCustomers.Update(dsCustomers, "Customers")

The load works fine, but When I hit the Save button after updating the
Custname textbox, nothing happens. Can you tell me what is wrong with the
code. What am I missing?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top