473,322 Members | 1,781 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,322 software developers and data experts.

DataTable.AcceptChanges

Hi All

I have a problem with getting a DataTable to submit changes back to the
database when calling AcceptChanges.
What I do is simplyfied this :
1) I set up a SqlDataAdapter with SelectCommand, InsertCommand,
UpdateCommand and DeleteCommand pointing to each a stored procedure.

Dim ad as new SqlDataAdapter
Dim ds as new DataSet
........ I setup the adapter 1) ........

ad.Fill(ds)

Dim dt as DataTable = ds.tables("MyTable")
Dim row as DataRow = dt.NewRow

row("field1") = "New String"
row("field2") = 234{int}
row("field3") = 212.34{single}

dt.Rows.Add(row)
dt.AcceptChanges()

This adds the new row to the DataTable just fine, but nothing happens in the
database when calling AcceptChanges.
Am I missing somethig completely here, or shouldn't I be able to insert the
new row into the database using AcceptChanges ??

Do I have to call ad.Update(ds) ??

This is not so easy since in my real code the DataAdapter and the actual
DataTable is placed/used in different places.
Does anyone have a solution to this ??

Thanks in advance

Allan



Jul 21 '05 #1
8 13746
Hi Allan,

AcceptChanges merely consolidates the changes once they are sucesfully
stored to database.
The right order would be:

Update(..)
AcceptChanges(..)

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Allan Bredahl" <a@bredahl.org> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi All

I have a problem with getting a DataTable to submit changes back to the
database when calling AcceptChanges.
What I do is simplyfied this :
1) I set up a SqlDataAdapter with SelectCommand, InsertCommand,
UpdateCommand and DeleteCommand pointing to each a stored procedure.

Dim ad as new SqlDataAdapter
Dim ds as new DataSet
....... I setup the adapter 1) ........

ad.Fill(ds)

Dim dt as DataTable = ds.tables("MyTable")
Dim row as DataRow = dt.NewRow

row("field1") = "New String"
row("field2") = 234{int}
row("field3") = 212.34{single}

dt.Rows.Add(row)
dt.AcceptChanges()

This adds the new row to the DataTable just fine, but nothing happens in the database when calling AcceptChanges.
Am I missing somethig completely here, or shouldn't I be able to insert the new row into the database using AcceptChanges ??

Do I have to call ad.Update(ds) ??

This is not so easy since in my real code the DataAdapter and the actual
DataTable is placed/used in different places.
Does anyone have a solution to this ??

Thanks in advance

Allan


Jul 21 '05 #2
That Means that I must have access to the DataAdapter if I want to be able
to commit the changes to the database ??
The problem is that I have a function that uses a DataAdapter to Fill my
DataSet, but I do not have access to this from where I need to commit the
changes to the DataSet/DataTable
thanks

Allan
"Miha Markic" <miha at rthand com> skrev i en meddelelse
news:Ov**************@tk2msftngp13.phx.gbl...
Hi Allan,

AcceptChanges merely consolidates the changes once they are sucesfully
stored to database.
The right order would be:

Update(..)
AcceptChanges(..)

Jul 21 '05 #3
Cor
Hi Allan,

If the dataadapter is not there, you can make a newone, it does not have to
be the same one.

And then exact as Miha wrote

xxxDataadpter.update(ds,"mytablename")

I hope this helps,

Cor
Update(..)
AcceptChanges(..)

Jul 21 '05 #4
Allan Bredahl <a@bredahl.org> wrote:
That Means that I must have access to the DataAdapter if I want to be able
to commit the changes to the database ??
Yes. The DataAdapter is the only thing that links the database and the
dataset.
The problem is that I have a function that uses a DataAdapter to Fill my
DataSet, but I do not have access to this from where I need to commit the
changes to the DataSet/DataTable


Then you need to change your design, I'm afraid.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5
Hi Cor

I know that is a posibility, but I must try to find the best and most clean
way to do it.
Maby the best solution is to go the MS way and follow there Application
Architecture guidelines, and work with a DataAccessLayer
Allan
"Cor" <no*@non.com> skrev i en meddelelse
news:Ov**************@TK2MSFTNGP11.phx.gbl...
Hi Allan,

If the dataadapter is not there, you can make a newone, it does not have to be the same one.

Jul 21 '05 #6
Hi Allan,

As other pointed out, the dataadapter is correct way.
The DAL itself uses them behind the scenes.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Allan Bredahl" <a@bredahl.org> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Hi Cor

I know that is a posibility, but I must try to find the best and most clean way to do it.
Maby the best solution is to go the MS way and follow there Application
Architecture guidelines, and work with a DataAccessLayer
Allan
"Cor" <no*@non.com> skrev i en meddelelse
news:Ov**************@TK2MSFTNGP11.phx.gbl...
Hi Allan,

If the dataadapter is not there, you can make a newone, it does not have

to
be the same one.


Jul 21 '05 #7
Yep, thats what I am thinking of.

Allan
"Miha Markic" <miha at rthand com> skrev i en meddelelse
news:OU**************@TK2MSFTNGP11.phx.gbl...
Hi Allan,

As other pointed out, the dataadapter is correct way.
The DAL itself uses them behind the scenes.

Jul 21 '05 #8
Allan,
In addition to all the other comments
Am I missing somethig completely here, or shouldn't I be able to insert the new row into the database using AcceptChanges ?? AcceptChanges changes the DataRow.RowState to Unchanged, it also updates the
DataRow Current & Original values.

http://msdn.microsoft.com/library/de...ClassTopic.asp

The DataAdpater.Update method does not bother looking at Unchanged rows. The
DataAdapter.Update method is what actually updates the database. Note
DataAdapter.Update will call DataRow.AcceptChanges...

You may want to read David Sceppa's book "Microsoft ADO.NET - Core
Reference" from MS Press. It is a good tutorial on ADO.NET to learn the
nuances of when & where to call AcceptChanges as well as when & where to
create DataAdapters. It is also an excellent desk reference once you know
ADO.NET.

Hope this helps
Jay

"Allan Bredahl" <a@bredahl.org> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl... Hi All

I have a problem with getting a DataTable to submit changes back to the
database when calling AcceptChanges.
What I do is simplyfied this :
1) I set up a SqlDataAdapter with SelectCommand, InsertCommand,
UpdateCommand and DeleteCommand pointing to each a stored procedure.

Dim ad as new SqlDataAdapter
Dim ds as new DataSet
....... I setup the adapter 1) ........

ad.Fill(ds)

Dim dt as DataTable = ds.tables("MyTable")
Dim row as DataRow = dt.NewRow

row("field1") = "New String"
row("field2") = 234{int}
row("field3") = 212.34{single}

dt.Rows.Add(row)
dt.AcceptChanges()

This adds the new row to the DataTable just fine, but nothing happens in the database when calling AcceptChanges.
Am I missing somethig completely here, or shouldn't I be able to insert the new row into the database using AcceptChanges ??

Do I have to call ad.Update(ds) ??

This is not so easy since in my real code the DataAdapter and the actual
DataTable is placed/used in different places.
Does anyone have a solution to this ??

Thanks in advance

Allan


Jul 21 '05 #9

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

Similar topics

3
by: Edward Mostrom | last post by:
I have 2 tables that have a relation between them. The parent table also has an expression in a column that sums the values in the child table. Both tables are hooked up to datagrids. ...
1
by: Mike | last post by:
I have an ASP.NET/VB app that updates values in a DataTable over the course of about 3 different pages. On the way out of the first of these pages, I explicitly build the DataTable from values in...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
5
by: fh | last post by:
Hello, I modifie one row of a datatable with this code DataRow drCurent = _dsDowntime.Tables.Rows; drCurent.BeginEdit(); drCurent=txbCAuto.Text; drCurent=txbbeg.Text; drCurent=txbEnd.Text;
8
by: Allan Bredahl | last post by:
Hi All I have a problem with getting a DataTable to submit changes back to the database when calling AcceptChanges. What I do is simplyfied this : 1) I set up a SqlDataAdapter with...
6
by: Danny Ni | last post by:
Hi, If I want to programatically add rows to a DataTable, do I call AcceptChanges per row? Or do I call AcceptChanges after all rows added? TIA
3
by: Ryan Liu | last post by:
Hi, In the .NET Framework SDK documentation, I can see DataRow.AcceptChanges method will throw RowNotInTableException exeception. And in DataTable.AcceptChanges(), the documentation does not...
2
by: =?Utf-8?B?Sm9iIExvdA==?= | last post by:
How can I reconcile changes between two data table and create a subset of those changes. I have two data tables with same schema which gets populated from two different xml files. I want to get...
2
by: Gurny | last post by:
I have a DataSet I am loading via the DataSet.Tables.Add() method. I call the AcceptChanges method on the DataTable first thing. Every thing looks good i.e. RowStates are all Unchanged. I then...
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.