473,651 Members | 3,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Failed to update datarow

Hello,

I tried to update a row in a table by using the datarow and data
adapter. Unfortunately, it doesn't update.

I try finding that datarow and set it to "dr", I can see dr could be
just an instance of the row, but aren't linked to the table. Is that
why it doesn't update? If not, what is missing? Please help!!!

Dim da As New SqlDataAdapter( "select * from Table1", cn)
Dim ds As New DataSet()
Dim dr As DataRow
da.Fill(ds, "Table1")
Dim keys(0) As DataColumn
keys(0) = ds.Tables(Table 1").Columns("ID ")
ds.Tables("Tabl e1").PrimaryK ey = keys
dr = ds.Tables("Tabl e1").Rows.Fin d (1)
dr.BeginEdit()

dr("F1") = "xxx"
dr.EndEdit()
dr.AcceptChange s()
da.Update(ds, "Table1")
Thanks in advance.
Wanda
Nov 21 '05 #1
6 5997
Wanda wrote:
Hello,

I tried to update a row in a table by using the datarow and data
adapter. Unfortunately, it doesn't update.

I try finding that datarow and set it to "dr", I can see dr could be
just an instance of the row, but aren't linked to the table. Is that
why it doesn't update? If not, what is missing? Please help!!!

Dim da As New SqlDataAdapter( "select * from Table1", cn)
Dim ds As New DataSet()
Dim dr As DataRow
da.Fill(ds, "Table1")
Dim keys(0) As DataColumn
keys(0) = ds.Tables(Table 1").Columns("ID ")
ds.Tables("Tabl e1").PrimaryK ey = keys
dr = ds.Tables("Tabl e1").Rows.Fin d (1)
dr.BeginEdit()

dr("F1") = "xxx"
dr.EndEdit()
dr.AcceptChange s()
da.Update(ds, "Table1")
Thanks in advance.
Wanda


I think you have to do da.Update before dr.AcceptChange s.
After AcceptChanges your DataRow is considered to be the original one so

it won't lead to an update
Nov 21 '05 #2
Remove the AcceptChanges() , if you leave it in, there will be nothing to
update as this sets the new or updated rows to the original rows and the
dataAdapter has nothing to work with.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Wanda" <wa*****@rogers .com> wrote in message
news:11******** *************** ***@posting.goo gle.com...
Hello,

I tried to update a row in a table by using the datarow and data
adapter. Unfortunately, it doesn't update.

I try finding that datarow and set it to "dr", I can see dr could be
just an instance of the row, but aren't linked to the table. Is that
why it doesn't update? If not, what is missing? Please help!!!

Dim da As New SqlDataAdapter( "select * from Table1", cn)
Dim ds As New DataSet()
Dim dr As DataRow
da.Fill(ds, "Table1")
Dim keys(0) As DataColumn
keys(0) = ds.Tables(Table 1").Columns("ID ")
ds.Tables("Tabl e1").PrimaryK ey = keys
dr = ds.Tables("Tabl e1").Rows.Fin d (1)
dr.BeginEdit()

dr("F1") = "xxx"
dr.EndEdit()
dr.AcceptChange s()
da.Update(ds, "Table1")
Thanks in advance.
Wanda

Nov 21 '05 #3
It doesn't work either if I do da.Update before dr.AcceptChange s,
instead I now get the following error message:

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

Thanks
Wanda


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4
Yes, you need to give the DataAdapter a valid UpdateCommand, you need the
following Commands generally.
SelectCommand
DeleteCommand
InsertCommand
UpdateCommand

Yours will be empty, this is why you are getting the error message.
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Wanda Li" <wa*****@rogers .com> wrote in message
news:uW******** ******@TK2MSFTN GP10.phx.gbl...
It doesn't work either if I do da.Update before dr.AcceptChange s,
instead I now get the following error message:

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

Thanks
Wanda


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #5
Do you mean I have to use

"Update Table1 Set F1 = 'xxx'" ???

Can I do something as simple as

dr.BeginEdit
dr("f1") = "xxx"
dr.EndEdit

then update???

I don't want to use the update statement since I have so many fields to
update, even I know I can do it in one update statement.

Thanks
Wanda


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #6
Wanda,

You can use the commandbuilder for this.

da.Fill(ds, "Table1")
Dim keys(0) As DataColumn
keys(0) = ds.Tables(Table 1").Columns("ID ")
ds.Tables("Tabl e1").PrimaryK ey = keys
dr = ds.Tables("Tabl e1").Rows.Fin d (1)
dr.BeginEdit()
dr("F1") = "xxx"
dr.EndEdit()
dim cmb as New xxxCommandBuild er(da) 'xxx = SQL or OleDb
da.Update(ds, "Table1")

'the acceptchanges is normally done by the dataadapter.

(The commandbuilder will not work with complex selectstatement s by instance
when there are more than 100 items in a datarow)

I hope this helps?

Cor

Nov 21 '05 #7

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

Similar topics

2
12663
by: Mojtaba Faridzad | last post by:
Hi, Please check these lines: DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet, "mytable"); DataRow row; row = dataSet.Tables.Rows; row.BeginEdit(); row = "555";
7
2577
by: Steve B. | last post by:
Does anyone know why the DA Update() would throw an exception? I moved the database but I updated the Conn and the DA, currently (trying)removing/replacing DS. Is there a another direction I should be looking in? Does it matter if I move columns in the grid (everything is a string anyways)? Does the DS need to be udated from the DT? *************** int rowNo = dg.CurrentRowIndex; dt = dt .Rows.BeginEdit();
9
21638
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message...
0
1389
by: Doug | last post by:
I've got a strongly-typed dataset with 2 related tables in it ("Staff" and "Roles"). I want to make a change to the parent Staff row and also to its child Role row. I'm having difficulty figuring out the best way to do this. First question: I can get myself a new instance of a row and make changes to it, but presumably that's then a separate object from the original dataset row. How do I reconcile my changes back to the dataset?
4
2006
by: CaptRR | last post by:
I think this is the right group to post to, so here goes. My problem is this, I cannot update the datarow to save my life. Been on this for 2 days now, and still am no closer to figuring it out than I was before. I'm basicly taking date from some text boxes, trying to put them into a datarow and using that datarow to update the database, but its not working. The btn_update is where I am sending the information back to the addclient...
15
1963
by: graham | last post by:
Hi all, <bitching and moaning section> I am asking for any help I can get here... I am at the end of my tether... I don;t consider myself a genius in any way whatsoever, but I do believe I have a logical way of thinking that has served me well during my years of application development with various tools... But having been working with VB.NET now for close to a month... I am beginning to doubt my abilities...
4
11156
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and call the following method. public void JobListDataTableFromAccessCommitChange() { System.Data.DataTable oChangeDataTable;
5
2593
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
3
2343
by: Fred Chateau | last post by:
Any obvious reason here why data is not being loaded into the database? SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand); SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter); dataAdapter.Fill(dataSet, "POI_Entity"); DataRow dataRow = dataSet.Tables.NewRow(); dataRow = 1; dataRow = dataSet.Identity.POI_Entity_ID; dataRow = dataSet.Identity.Chain_ID;
0
8361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8278
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8807
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8466
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7299
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.