Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Update records in a Dataset... How? Please help

Reply
Thread Tools

Update records in a Dataset... How? Please help

 
 
=?Utf-8?B?Q2FsdmluIEtE?=
Guest
Posts: n/a
 
      11-08-2005
Hi everyone,
I know the solution to my problem is probably very simple but I just can't
seem to figure out how to do it. My problem is, I have an XML file as a
datastore, I read it into a dataset for data manipulation and update the
dataset with some edited data from the screen. However, I can't seem to make
the changes "stick" in the dataset.
Following is my code snippet:

DataSet dsCOTs = new DataSet();
dsCOTs.ReadXml(Server.MapPath("../COTS.xml"));
dsCOTs.Tables[0].PrimaryKey = new System.Data.DataColumn[]
{dsCOTs.Tables[0].Columns["cotid"]};
DataRow drCOT = dsCOTs.Tables[0].Rows.Find(this.txtCOTID.Text);
if (drCOT != null)
{
drCOT.BeginEdit();
drCOT["claimed"] = "Y";
drCOT.EndEdit();
}
dsCOTs.AcceptChanges();
System.Data.SqlClient.SqlDataAdapter da = new
System.Data.SqlClient.SqlDataAdapter();
da.Update(dsCOTs, "cot");

and the COTs.xml looks like:
<COTS>
<cot>
<id>1234</id>
<name>abcd</name>
<claimed>N</claimed>
</cot>
<cot>
<id>5678</id>
<name>efgh</name>
<claimed>N</claimed>
</cot>
</COTS>

Can someone show me how to update the "claimed" field to "Y" please. Any
suggestion is greatly appreciated, as always.

Calvin
 
Reply With Quote
 
 
 
 
Daren Hawes
Guest
Posts: n/a
 
      11-08-2005
You should NEVER call AcceptChanges before calling Update because if you do
then the changes you have made will not be committed back to the database.
When you call Update, all rows with a RowState of Deleted, Added or Modified
will be reconciled to the database. When you call AcceptChanges, ALL rows
have their RowState set back to Unchanged so no data will be reconciled with
the database. Every call to Update includes an implicit call to
AcceptChanges, so you shouldn't have to call it yourself. There are very
few circumstances where an explicit call to AcceptChanges would be required.

If you are getting concurrency violations it means that some of the data you
are trying to update or delete does not match the existing data in the
database. Chances are you have screwed up you SQL somewhere along the line,
or maybe added your parameters incorrectly.


"Calvin KD" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi everyone,
> I know the solution to my problem is probably very simple but I just can't
> seem to figure out how to do it. My problem is, I have an XML file as a
> datastore, I read it into a dataset for data manipulation and update the
> dataset with some edited data from the screen. However, I can't seem to
> make
> the changes "stick" in the dataset.
> Following is my code snippet:
>
> DataSet dsCOTs = new DataSet();
> dsCOTs.ReadXml(Server.MapPath("../COTS.xml"));
> dsCOTs.Tables[0].PrimaryKey = new System.Data.DataColumn[]
> {dsCOTs.Tables[0].Columns["cotid"]};
> DataRow drCOT = dsCOTs.Tables[0].Rows.Find(this.txtCOTID.Text);
> if (drCOT != null)
> {
> drCOT.BeginEdit();
> drCOT["claimed"] = "Y";
> drCOT.EndEdit();
> }
> dsCOTs.AcceptChanges();
> System.Data.SqlClient.SqlDataAdapter da = new
> System.Data.SqlClient.SqlDataAdapter();
> da.Update(dsCOTs, "cot");
>
> and the COTs.xml looks like:
> <COTS>
> <cot>
> <id>1234</id>
> <name>abcd</name>
> <claimed>N</claimed>
> </cot>
> <cot>
> <id>5678</id>
> <name>efgh</name>
> <claimed>N</claimed>
> </cot>
> </COTS>
>
> Can someone show me how to update the "claimed" field to "Y" please. Any
> suggestion is greatly appreciated, as always.
>
> Calvin



 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2FsdmluIEtE?=
Guest
Posts: n/a
 
      11-08-2005
Thanks so much Daren. I managed to get it to work by calling the
AcceptChanges method of the dataset and discard the Update method of the
dataadaptor altogether.
Thanks again.
Calvin

"Daren Hawes" wrote:

> You should NEVER call AcceptChanges before calling Update because if you do
> then the changes you have made will not be committed back to the database.
> When you call Update, all rows with a RowState of Deleted, Added or Modified
> will be reconciled to the database. When you call AcceptChanges, ALL rows
> have their RowState set back to Unchanged so no data will be reconciled with
> the database. Every call to Update includes an implicit call to
> AcceptChanges, so you shouldn't have to call it yourself. There are very
> few circumstances where an explicit call to AcceptChanges would be required.
>
> If you are getting concurrency violations it means that some of the data you
> are trying to update or delete does not match the existing data in the
> database. Chances are you have screwed up you SQL somewhere along the line,
> or maybe added your parameters incorrectly.
>
>
> "Calvin KD" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi everyone,
> > I know the solution to my problem is probably very simple but I just can't
> > seem to figure out how to do it. My problem is, I have an XML file as a
> > datastore, I read it into a dataset for data manipulation and update the
> > dataset with some edited data from the screen. However, I can't seem to
> > make
> > the changes "stick" in the dataset.
> > Following is my code snippet:
> >
> > DataSet dsCOTs = new DataSet();
> > dsCOTs.ReadXml(Server.MapPath("../COTS.xml"));
> > dsCOTs.Tables[0].PrimaryKey = new System.Data.DataColumn[]
> > {dsCOTs.Tables[0].Columns["cotid"]};
> > DataRow drCOT = dsCOTs.Tables[0].Rows.Find(this.txtCOTID.Text);
> > if (drCOT != null)
> > {
> > drCOT.BeginEdit();
> > drCOT["claimed"] = "Y";
> > drCOT.EndEdit();
> > }
> > dsCOTs.AcceptChanges();
> > System.Data.SqlClient.SqlDataAdapter da = new
> > System.Data.SqlClient.SqlDataAdapter();
> > da.Update(dsCOTs, "cot");
> >
> > and the COTs.xml looks like:
> > <COTS>
> > <cot>
> > <id>1234</id>
> > <name>abcd</name>
> > <claimed>N</claimed>
> > </cot>
> > <cot>
> > <id>5678</id>
> > <name>efgh</name>
> > <claimed>N</claimed>
> > </cot>
> > </COTS>
> >
> > Can someone show me how to update the "claimed" field to "Y" please. Any
> > suggestion is greatly appreciated, as always.
> >
> > Calvin

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
J2ME: Phone Book for 3,000 records.. please help me Sky Rhythm Java 3 12-01-2006 04:26 PM
Simple query returns 0 records in asp, but all records in vbscript masg0013@gmail.com ASP General 3 11-02-2006 09:23 AM
Delete records or update records Dan ASP General 1 05-10-2004 01:25 PM
match muliple header records to associated detail records Luke Airig XML 0 12-31-2003 12:06 AM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments