473,397 Members | 2,099 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,397 software developers and data experts.

Dataadabter update command throws error

In the past, I have filled a datagrid with data from an Access database
table using a data adapter and dataset, where I used the OleDbCommandBuilder
to have the program create the insert, delete and update commands
automatically for the dataadapter. I think those database tables had no
more than 10 or 12 fields. Then to save the changes in the datagrid to the
database, I simply evoked the dataadapter update command. No problems.

Yesterday, I tried the same scenario with a database someone sent me and had
no luck. When I should try to save the data after changes had been made in
the datagrid using the dataadapter update command, I got the following
error:

Update requires a valid UpdateCommand when passed DataRow collection with
modified rows.

Short of trying to write my own update command, I can find no way of
correcting this. By the way, this new database table has 22 fields. This
makes me wonder if the OleDbCommandBuilder goes flakey when you have more
than just a few fields?

Also, has anyone else encountered this and have a solution?

To get a program that would do what I needed, I added a reference to ADODB
to the project and used that to do my save with no problems. But I would
like to use the simpler solution of the dataadapter update.
Dec 11 '05 #1
4 1482
William,

All datawizards in Visual StudioNet (I am not sure for version 2005) go
until 100 datafields in a database. Therefore your commandbuilder should
normally work. (All wizards as the commandbuilder can only create straight
single table update, insert and deletecommands)

If you cannot find it, show than some code around that commandbuilder.
(first copy it in a notebook, than back in the message or use the program
from Armin Zingler)

http://people.freenet.de/armin.zingl...dPlainText.zip

I hope this helps,

Cor
Dec 12 '05 #2
Everything is done in code, so I see no way to get any text associated with
the dataadapter update command since it doesn't know that fields it will
have to deal with until I run the code and the command builder does its
thing.

Here is the code that loads the database and fills a data set, ds2, with the
data from the table Main which I then use as the datasource for a datagrid.
The datagrid displays the data fine. But as mentioned in the previous
message, the dataadapter cannot update the database because it claims there
is no update command.
dc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
"AddressData.mdb"
dc.Open()
Dim StrSQL As String = "SELECT * from Main"
Dim objCommand As New Data.OleDb.OleDbCommand(StrSQL, dc)
Dim da As New Data.OleDb.OleDbDataAdapter
da.Fill(ds2, "Main")
Dim custCB As Data.OleDb.OleDbCommandBuilder = New
Data.OleDb.OleDbCommandBuilder(da)
custCB.QuotePrefix = "["
custCB.QuoteSuffix = "]"

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl...
William,

All datawizards in Visual StudioNet (I am not sure for version 2005) go
until 100 datafields in a database. Therefore your commandbuilder should
normally work. (All wizards as the commandbuilder can only create straight
single table update, insert and deletecommands)

If you cannot find it, show than some code around that commandbuilder.
(first copy it in a notebook, than back in the message or use the program
from Armin Zingler)

http://people.freenet.de/armin.zingl...dPlainText.zip

I hope this helps,

Cor

Dec 12 '05 #3
William,

This is correct except if the dataadapter.update is in another method.

(The dataadapter has now only scoop inside the method and will be given to
the GC to release at the end of the method)

Therefore where do you have this and where do you have the update located?

Cor

"William LaMartin" <la******@tampabay.rr.com> schreef in bericht
news:uY**************@TK2MSFTNGP14.phx.gbl...
Everything is done in code, so I see no way to get any text associated
with the dataadapter update command since it doesn't know that fields it
will have to deal with until I run the code and the command builder does
its thing.

Here is the code that loads the database and fills a data set, ds2, with
the data from the table Main which I then use as the datasource for a
datagrid. The datagrid displays the data fine. But as mentioned in the
previous message, the dataadapter cannot update the database because it
claims there is no update command.
dc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
"AddressData.mdb"
dc.Open()
Dim StrSQL As String = "SELECT * from Main"
Dim objCommand As New Data.OleDb.OleDbCommand(StrSQL, dc)
Dim da As New Data.OleDb.OleDbDataAdapter
da.Fill(ds2, "Main")
Dim custCB As Data.OleDb.OleDbCommandBuilder = New
Data.OleDb.OleDbCommandBuilder(da)
custCB.QuotePrefix = "["
custCB.QuoteSuffix = "]"

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl...
William,

All datawizards in Visual StudioNet (I am not sure for version 2005) go
until 100 datafields in a database. Therefore your commandbuilder should
normally work. (All wizards as the commandbuilder can only create
straight single table update, insert and deletecommands)

If you cannot find it, show than some code around that commandbuilder.
(first copy it in a notebook, than back in the message or use the program
from Armin Zingler)

http://people.freenet.de/armin.zingl...dPlainText.zip

I hope this helps,

Cor


Dec 12 '05 #4
You hit the nail on the head. Thanks very much.

I had given the dataadapter scope of the entire form (Protected da As New
Data.oledb.OleDbDataAdapter at the top of the form). Then without realizing
it, I placed the code "Dim da As New Data.oledb.OleDbDataAdapter" in the
button_click event for loading the data. Once I removed that redundant
code, everything worked fine. I must have looked at that code for hours in
various permutations without noticing the problem

Thanks again

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
William,

This is correct except if the dataadapter.update is in another method.

(The dataadapter has now only scoop inside the method and will be given to
the GC to release at the end of the method)

Therefore where do you have this and where do you have the update located?

Cor

"William LaMartin" <la******@tampabay.rr.com> schreef in bericht
news:uY**************@TK2MSFTNGP14.phx.gbl...
Everything is done in code, so I see no way to get any text associated
with the dataadapter update command since it doesn't know that fields it
will have to deal with until I run the code and the command builder does
its thing.

Here is the code that loads the database and fills a data set, ds2, with
the data from the table Main which I then use as the datasource for a
datagrid. The datagrid displays the data fine. But as mentioned in the
previous message, the dataadapter cannot update the database because it
claims there is no update command.
dc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
"AddressData.mdb"
dc.Open()
Dim StrSQL As String = "SELECT * from Main"
Dim objCommand As New Data.OleDb.OleDbCommand(StrSQL, dc)
Dim da As New Data.OleDb.OleDbDataAdapter
da.Fill(ds2, "Main")
Dim custCB As Data.OleDb.OleDbCommandBuilder = New
Data.OleDb.OleDbCommandBuilder(da)
custCB.QuotePrefix = "["
custCB.QuoteSuffix = "]"

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl...
William,

All datawizards in Visual StudioNet (I am not sure for version 2005) go
until 100 datafields in a database. Therefore your commandbuilder should
normally work. (All wizards as the commandbuilder can only create
straight single table update, insert and deletecommands)

If you cannot find it, show than some code around that commandbuilder.
(first copy it in a notebook, than back in the message or use the
program from Armin Zingler)

http://people.freenet.de/armin.zingl...dPlainText.zip

I hope this helps,

Cor



Dec 12 '05 #5

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

Similar topics

3
by: Mohammed Mazid | last post by:
Can anyone please help me here? Basically I have modified the source code and understood it but when I update a record in the db using a JSP, it gives me an error "The flight you selected does...
2
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the...
2
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the...
15
by: judge82 | last post by:
I made sure I closed all the bracket, why do i still get the error. on line 360, 424, 425 and 607 Please help /* * ShopCartServletHW3.java *
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.