Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: RE: Insert Multiple records to DB


Message #1 by "Graham Dobson" <grahamdo@a...> on Mon, 2 Sep 2002 12:01:54 -0400
Actually the question implied that the records were already inserted, and
asked how to resync the DataSet with the database. To round out your
description of AcceptChanges further, only added and modified records are
changed to 'unchanged' by calling AcceptChanges, deleted rows are removed.
The AcceptRejectRule is also fired against any foreign key constraints
present.  In fact changes made to a DataSet are not realized until you call
AcceptChanges on the appropriate DataTable or DataSet.
  I found this, in Bob Beauchamin's Essential ADO.NET, to be
interesting--the DataAdapter's Fill method  populates a DataSet and
automatically calls AcceptChanges on the DataSet. If you do not want this
behavior (perhaps you are populating a DataSet from multiple data stores and
updating to another data store)  you can us the DataAdapter property
AcceptChangesDuringFill and set it to false (it defaults to true).  The
resulting rows will appear 'newly changed' rather than 'unchanged', and you
can write your rows back out to your data store through Insert or Update
commands.

As far as updating or inserting data in ADO.NET there are a myriad of
methods and techniques to accomplish this.  None of which are as simple as
calling AcceptChanges().  There is a message missing from this thread which
erroneously suggested a method name not quite like AcceptChanges, and I was
merely wondering if the poster intended AcceptChanges.  Perhaps I should
have replied to that message, rather than the original.

Graham


-----Original Message-----
From: Richard Ainsley [mailto:rainsley@p...]
Sent: Saturday, August 31, 2002 4:19 AM
To: ADO.NET
Subject: [ado_dotnet] RE: Insert Multiple records to DB


Accept changes does NOT update the database.  It changes the record status
settings to "unchanged" on each record (scope varies depending on the object
whose method you invoke).

To update the data source requires more than that.  Remember you have a
DISCONNECTED DATASET.  You must supply the correct SQL script to update the
data source.  The easiest way to do that is to use a data adapter.  The data
adapter stores the SQL scripts needed to insert, update and delete records.
The data rows each have a rowstate property which tracks if that record is a
newly added record, updated record, delelete record, or an unchanged record.
When you invoke the dataset.Update method, the data adapter scans the
records of one table and uses the appropriate script needed to make the data
source update.  Or, you can do it all yourself by executing a command
object.

That also means if you hae several tables in the data set, that you need to
use more than one data adapter.  If your updates need to participate in a
transaction, the connection object works just like the ADO connection object
in VB6 which also manages trransactions.  Just keep in mind that you can't
nest transactions....

Richard Ainsley

----- Original Message -----
From: "Graham Dobson" <grahamdo@a...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Thursday, August 29, 2002 8:51 PM
Subject: [ado_dotnet] RE: Insert Multiple records to DB


> AcceptChanges() ?
>
> Graham
>
>
>
> -----Original Message-----
> From: veluswamy [mailto:vellu125@y...]
> Sent: Thursday, August 29, 2002 5:17 AM
> To: ADO.NET
> Subject: [ado_dotnet] Insert Multiple records to DB
>
>
> Hi all,
> I have a dataset with multiple records inserted.How do i Sync this with
> the DB.
>
> Thanks
> velu
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923
>
>
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923


---
ASP.NET Distributed Data Applications
This book will inspire you with a range of ideas on how data
can be used to drive Web applications, and how that data can
be most effectively utilized at each level of the design.
Inefficient data use leads to the sort of slow, unresponsive
Web applications that nobody enjoys using. By making good use
of both server and client-side code, we can solve these
problems. This book will arm you with the techniques you need
to build Web applications that fly.
http://www.wrox.com/ACON11.asp?ISBN=1861004923


  Return to Index