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

What's going on in this ADO2 code

VB.NET 2005 and ADO2.NET

After years of VB6 and ADO coding, I'm checking out ADO2.NET.

I spent several hours trying to figure out why the line:
objDataAdapter.Update(objDataSet, "myTable")

caused this error:
Update requires a valid UpdateCommand when passed DataRow collection with
modified rows.

In this code:
objDataSet.Tables("myTable").Rows(1).EndEdit()
If objDataSet.HasChanges Then
objDataAdapter.Update(objDataSet, "myTable") <--error here
End If

After much Google, I found that adding this line solved the problem:
Dim cb As New OleDb.OleDbCommandBuilder(objDataAdapter)

So the working code is:
Dim cb As New OleDb.OleDbCommandBuilder(objDataAdapter)
objDataSet.Tables("myTable").Rows(1).EndEdit()
If objDataSet.HasChanges Then
objDataAdapter.Update(objDataSet, "myTable")
End If

What's going on here? What is "cb" doing to the DataAdapter?

Mar 3 '06 #1
3 3152
It's generate the update/insert/delete commands so that the adapter knows
what queries to run.

You either need to set the InsertCommand, UpdateCommand, DeleteCommand
properties to call appropriate queries or stored procedures with all the
parameters set up correctly, or use the commandbuilder and have it do it for
you.

There are issues with both approaches, and there have been many discussions
on the subject in this newsgroup.

"phonl" <ph***@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
VB.NET 2005 and ADO2.NET

After years of VB6 and ADO coding, I'm checking out ADO2.NET.

I spent several hours trying to figure out why the line:
objDataAdapter.Update(objDataSet, "myTable")

caused this error:
Update requires a valid UpdateCommand when passed DataRow collection with
modified rows.

In this code:
objDataSet.Tables("myTable").Rows(1).EndEdit()
If objDataSet.HasChanges Then
objDataAdapter.Update(objDataSet, "myTable") <--error here
End If

After much Google, I found that adding this line solved the problem:
Dim cb As New OleDb.OleDbCommandBuilder(objDataAdapter)

So the working code is:
Dim cb As New OleDb.OleDbCommandBuilder(objDataAdapter)
objDataSet.Tables("myTable").Rows(1).EndEdit()
If objDataSet.HasChanges Then
objDataAdapter.Update(objDataSet, "myTable")
End If

What's going on here? What is "cb" doing to the DataAdapter?

Mar 3 '06 #2
I meant to say the subject has been discussed many times in the adonet
newsgroup.

"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:Om**************@TK2MSFTNGP11.phx.gbl...
It's generate the update/insert/delete commands so that the adapter knows
what queries to run.

You either need to set the InsertCommand, UpdateCommand, DeleteCommand
properties to call appropriate queries or stored procedures with all the
parameters set up correctly, or use the commandbuilder and have it do it
for you.

There are issues with both approaches, and there have been many
discussions on the subject in this newsgroup.

"phonl" <ph***@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
VB.NET 2005 and ADO2.NET

After years of VB6 and ADO coding, I'm checking out ADO2.NET.

I spent several hours trying to figure out why the line:
objDataAdapter.Update(objDataSet, "myTable")

caused this error:
Update requires a valid UpdateCommand when passed DataRow collection with
modified rows.

In this code:
objDataSet.Tables("myTable").Rows(1).EndEdit()
If objDataSet.HasChanges Then
objDataAdapter.Update(objDataSet, "myTable") <--error here
End If

After much Google, I found that adding this line solved the problem:
Dim cb As New OleDb.OleDbCommandBuilder(objDataAdapter)

So the working code is:
Dim cb As New OleDb.OleDbCommandBuilder(objDataAdapter)
objDataSet.Tables("myTable").Rows(1).EndEdit()
If objDataSet.HasChanges Then
objDataAdapter.Update(objDataSet, "myTable")
End If

What's going on here? What is "cb" doing to the DataAdapter?


Mar 3 '06 #3
Hi Phonl,

Thanks for posting!

As Marina mentioned, the issue is caused when UpdateCommand isn't specified
for the DataAdapter. The following KB article demonstrates how to resolve
the problem when the error occurs:
http://support.microsoft.com/default...en-us%3B310376

In addition, I think the specification from MSDN give us more details about
the current issue:
http://msdn2.microsoft.com/en-us/library/a19c81fk.aspx

I hope this will be helpful!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
updated on February 14, 2006. Please complete a re-registration process
by entering the secure code mmpng06 when prompted. Once you have
entered the secure code mmpng06, you will be able to update your profile
and access the partner newsgroups.
================================================== ====
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====

Mar 6 '06 #4

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
2
by: Brian Shearer | last post by:
Hi, can anyone assist... We have developed an application in .NET using ADO2.7 and have discovered that the production platform only has ADO2.5. We are connecting to SQL2000. Can anyone...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
13
by: Kyle Adams | last post by:
I don't know where is the right place to ask this so I will start here. Can someone explain to me what these represent? I think they all have to do with the middleware level, but I really don't...
63
by: Jake Barnes | last post by:
In the course of my research I stumbled upon this article by Alex Russel and Tim Scarfe: http://www.developer-x.com/content/innerhtml/default.html The case is made that innerHTML should never...
2
by: phonl | last post by:
I'm new to ADO2.net. This must be easy, but how would I do get this value in ADO2.net? VB6 ADO: msgbox myRecordset!myField In ADO2.net I have a TableAdapter, DataSet, and BindingSource...
6
by: phonl | last post by:
In ADO2, how would I find the position of "x" in: myDataSet.Tables("myTable").Rows(x).Item("myField") = "NewValue" I want to manipulate some data in the current row in my dataset, but it seems...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.