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("MyTa ble")
Dim row as DataRow = dt.NewRow
row("field1") = "New String"
row("field2") = 234{int}
row("field3") = 212.34{single}
dt.Rows.Add(row )
dt.AcceptChange s()
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 13786
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.or g> wrote in message
news:%2******** *******@TK2MSFT NGP11.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("MyTa ble") Dim row as DataRow = dt.NewRow
row("field1") = "New String" row("field2") = 234{int} row("field3") = 212.34{single}
dt.Rows.Add(row ) dt.AcceptChange s() 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******** ******@tk2msftn gp13.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.u pdate(ds,"mytab lename")
I hope this helps,
Cor Update(..) AcceptChanges(. .)
Allan Bredahl <a@bredahl.or g> 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.co m> 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******** ******@TK2MSFTN GP11.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.or g> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l... 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******** ******@TK2MSFTN GP11.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******** ******@TK2MSFTN GP11.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.RowStat e to Unchanged, it also updates the
DataRow Current & Original values. http://msdn.microsoft.com/library/de...ClassTopic.asp
The DataAdpater.Upd ate method does not bother looking at Unchanged rows. The
DataAdapter.Upd ate method is what actually updates the database. Note
DataAdapter.Upd ate will call DataRow.AcceptC hanges...
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.or g> wrote in message
news:%2******** *******@TK2MSFT NGP11.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("MyTa ble") Dim row as DataRow = dt.NewRow
row("field1") = "New String" row("field2") = 234{int} row("field3") = 212.34{single}
dt.Rows.Add(row ) dt.AcceptChange s() 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.
Everything seems to work fine as far as adding and changing rows in the
child table. But if I delete a row in the child table that has a value
in it, the...
|
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 a
DataGrid, and set the PrimaryKey of the DataTable to be the first cell
in the grid (which is a UserID value). I then store the DataTable in
a...
|
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 datacolumns do not trigger
their expression when other columns from which the expressions are derived
are updated. Below is a basic example of what...
|
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 SelectCommand, InsertCommand,
| |
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 mention it will
throw any exception, but in my code (multi-thread), I see it throw
exceptions at two situations:
dr =...
|
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 hold of missing & changed rows in
first table from second table. Tables have ID as primary key.
Thanks
|
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 bind this datatable to an Infragistics Calendarinfo AppointmentsDataBinding object. Everything still going smooth. I run the app and update an...
|
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...
|
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. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |