473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Dataadapter

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
Nov 20 '05 #1
6 1365
Does your table have a primary key? It'll need a key to generate the update
logic
"Andrew Cooper" <ae******@earthlink.net> wrote in message
news:40**********@newspeer2.tds.net...
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

Nov 20 '05 #2
Yes, it is an Access Database with a primary key defined for the Table.

Andrew

"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...
Does your table have a primary key? It'll need a key to generate the update logic
"Andrew Cooper" <ae******@earthlink.net> wrote in message
news:40**********@newspeer2.tds.net...
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


Nov 20 '05 #3
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)
"Andrew Cooper" <ae******@earthlink.net> wrote in message
news:40**********@newspeer2.tds.net...
Yes, it is an Access Database with a primary key defined for the Table.

Andrew

"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...
Does your table have a primary key? It'll need a key to generate the update
logic
"Andrew Cooper" <ae******@earthlink.net> wrote in message
news:40**********@newspeer2.tds.net...
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



Nov 20 '05 #4
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
Nov 20 '05 #5
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" <ae******@charter.net> wrote in message
news:10*************@corp.supernews.com...
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

Nov 20 '05 #6
That fixed it! You rock. Thanks!

Andrew
"William Ryan eMVP" <bi**@NoSp4m.devbuzz.com> wrote in message
news:u9**************@TK2MSFTNGP12.phx.gbl...
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" <ae******@charter.net> wrote in message
news:10*************@corp.supernews.com...
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


Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: hch | last post by:
dataAdapter.Update(data, "TableName") won’t work! I was about to deploy my first website on the Internet only to discover that the dataAdapter.Update() throws the Server Error in the third...
3
by: Stephen Noronha | last post by:
I have a question, please correct me if I am wrong. I am assuming that a dataadapter establishes a connection and after filling the dataset or datatable or whatever, will close the connection to...
6
by: Geoff Pennington | last post by:
I have a class method that returns a DataAdapter. I want to access the table(s) contained in the DataAdapter. Of course, accessing the DataSets would be good enough, because I could get the tables...
13
by: Doug Bell | last post by:
Hi, I thought I had this sorted this morning but it is still a problem. My application has a DataAccess Class. When it starts, it: Connects to a DB (OLE DB) If it connects it uses an...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
2
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
7
by: Max | last post by:
I've included the needed tables in the DataSource. Those tables that are bound to controls I can workwith. But how do you get access to the DataAdaptors that are not bound? me.Dataset1.table...
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
3
by: Rich | last post by:
What is the diffeence bewtween a dataAdapter.InsertCommand and dataAdapter.SelectCommand (and dataAdapter.UpdateCommand for that matter)? Dim da As SqlDataAdapter conn.Open da.SelectCommand =...
2
by: BobLewiston | last post by:
I can read in an SQL table ("Person.Contact") from AdventureWorks and step through it one row at a time, but when I try to save a record, either one I'm inserting or one I'm editting, I get the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.