Dataadapter

  • Thread starter Thread starter Andrew Cooper
  • Start date Start date
A

Andrew Cooper

Greetings,

I'm running into a little problem with a Dataadapter object. I'm using it
to fill a Datatable but when I later try to Update the database using the
Dataadapter.Update method, I get an error saying that the INSERT INTO
statement is not correct. When I look at the CommandText of the Insert
command, I get that it isn't set to anything even though I used a
Commandbuilder to populate it. Any help would be appreciated. Here's my
code...

<code>
....
Private oPlayersDA As New OleDbDataAdapter()

Private oCmdBldr As OleDbCommandBuilder

Private oDataSet As New DataSet()

.... some code here ...

oPlayersDA.SelectCommand = New OleDbCommand()

With oPlayersDA.SelectCommand

.CommandType = CommandType.Text

.CommandText = "SELECT * FROM Players"

.Connection = oConn

.CommandTimeout = 30

End With

oCmdBldr = New OleDbCommandBuilder(oPlayersDA)

oPlayersDA.Fill(oDataSet, "Players")

.... some code here ...

oPlayersDA.Update(oDataSet, "Players")

</code>

I'm at a loss...



Andrew
 
Does your table have a primary key? It'll need a key to generate the update
logic
 
Yes, it is an Access Database with a primary key defined for the Table.

Andrew
 
Andrew:

That's normally the problem, can you show me the field names? One other
thing that can cause some goofy behavior is the existence of reserved words
for field names (the query will work fine in Access but chokes when you fire
an update in ADO.NET)
 
Sure... the table has the following fields:

DBRef as Long
Name as String
Desc as String
Flags as Long
Created as Date
LastChanged as Date
WhoChanged as Date
Owner As Long
Nick as String
Location as Long
Password as String
Sex as Long

The DBref field is the Primary Key.

Andrew
 
Andrew:

There are a few reserved words in there...and that usually causes problems
with ADO.NET... Typically you can wrap them in brackets [reserved fied name]
but that's just a bandaid. I'd change Desc to _Desc or something else that
isn't reserved, and Password. I don't have the full list in front of me but
I think Name may also be a problem.

HTH,

Bill
 
That fixed it! You rock. Thanks!

Andrew


William Ryan eMVP said:
Andrew:

There are a few reserved words in there...and that usually causes problems
with ADO.NET... Typically you can wrap them in brackets [reserved fied name]
but that's just a bandaid. I'd change Desc to _Desc or something else that
isn't reserved, and Password. I don't have the full list in front of me but
I think Name may also be a problem.

HTH,

Bill
Andrew Cooper said:
Sure... the table has the following fields:

DBRef as Long
Name as String
Desc as String
Flags as Long
Created as Date
LastChanged as Date
WhoChanged as Date
Owner As Long
Nick as String
Location as Long
Password as String
Sex as Long

The DBref field is the Primary Key.

Andrew
 
Back
Top