ADO.NET - Update Problem

S

Sergio Terenas

Sorry if this is too basic but I've been banging my head on this for some time now.

I'm using Visual Stucio 2003, VB.NET. I'm able to build a win form with an OleDBConnection, DataAdapter and DataSet against an Access 2003 database using Jet 4.0.
I'm able to browse, move forward, backwards, show the contents on text boxes, etc.

There's just no way I can update the database even though I'm using the command:

DataAdapter1.Update(dsDataSet1) (I'm sure the names are correct in the progam!). This command fires if I press the "Update" button.

I'm using Office 2003. I've saved the db using the 2003 format, tried with Access 2000-2002 format, I've tried making changes to the parameters on the connection string but nothing seems to make it update the table.

Very simple table:
ID Text 50
Name Text 50

I'm using the wizards for the data part of the program. Any ideas anyone ? Am I the only one with this issue ?

Thanks a lot!

ST
 
E

Elton Wang

Hi Sergio,

Do you create InsertCommand, DeleteCommand, and
UpdateCommand (or simply create OleDbCommandBuilder
object) for
DataAdapter before you call the DataAdapter's Update
method?


Elton Wang
(e-mail address removed)

-----Original Message-----
Sorry if this is too basic but I've been banging my head on this for some time now.

I'm using Visual Stucio 2003, VB.NET. I'm able to build
a win form with an OleDBConnection, DataAdapter and
DataSet against an Access 2003 database using Jet 4.0.
I'm able to browse, move forward, backwards, show the contents on text boxes, etc.

There's just no way I can update the database even though I'm using the command:

DataAdapter1.Update(dsDataSet1) (I'm sure the names are
correct in the progam!). This command fires if I press
the "Update" button.
I'm using Office 2003. I've saved the db using the 2003
format, tried with Access 2000-2002 format, I've tried
making changes to the parameters on the connection string
but nothing seems to make it update the table.
Very simple table:
ID Text 50
Name Text 50

I'm using the wizards for the data part of the program.
Any ideas anyone ? Am I the only one with this issue ?
 
S

Sergio Terenas

Hi Elton,

I created all the commands using the wizard but I'm not using them in the
code. The code has only the .update command to update. Should I add
anything else to the code ?

It's funny as I've got two books on ADO.NET that say that with 2 lines of
code you can write a DB application. One command would be the .FILL and the
other one the .UPDATE. Am I missing something ?

Is there any code somewhere that shows what code I should have on the
"Update" button to actually update the data ? I thought .update was enough
(I'm using the wizards)...

Thanks for your reply.

ST
 
E

Elton Wang

If data source of your select query is from single table,
it's simple. Do something like following:

OleDbDataAdapter da = new OleDbDataAdapter(sqlSelectQuery,
connection);
// CommandBuilder will automatically create UpadateCommand
based on sqlSelectQuery
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
da.Fill(ds,tableName);
// process datatable
....
da.Update(ds,tableName);

HTH

Elton Wang
 
S

Sergio Terenas

The answer to my own question is to add the BindingContext... line before
the update. Enclose the code below...

Thanks to the folks at Microsoft ADO.NET chat today!

Geetings,

ST

Try
BindingContext(DsTest1.Tables(0)).EndCurrentEdit()
OleDbDataAdapter1.Update(DsTest1.TEST_TABLE)
Catch ex As Exception
MsgBox(ex)
End Try
 

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