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 8 13771
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
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(..)
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(..)
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
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.
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.
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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
...
|
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...
|
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...
|
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;
|
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...
| |
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
|
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...
|
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...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
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: 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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |