Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Database from Dataset

Status
Not open for further replies.

Eli20

Programmer
Oct 30, 2003
119
MX
hi, i have the following method:

Code:
private void Sincronize(DataSet ds){
     string connString=server="localhost"; uid=sa;pwd=;database=myDatabase"
     SqlConnection conn=new SqlConnection(connString);
     SqlDataAdapter da=new SqlDataAdapter("Select * from orders", conn);
     DataSet ds1=new Dataset();
     da.Fill(ds1, "orders");
     ds1.Merge(ds, false, MissimgSchemaAction.Add);
     
     da.Update(ds1, "orders");
}

what im trying to do is to copy the contents of the dataset i get on the method call to my database. that dataset comes from the same table in another database.
ive checked and in ds1 i get what i want, but the dataadapter is not updating my database, can anybody help me??

thank you

Eli
 
Eli,

You need to commit the changes to the dataset after calling the update().

Add this to your code and it should work fine -->

ds.AcceptChanges();



Good Luck
 
i tried that, and nothing happens, i also tried to use da.AcceptChangesDuringFill=false

but i still get nothing..

thank you

Eli
 
Eli,
It seems that the DataSet's Merge method leaves the HasChanges property as False, and therefore calling da.Update(ds1, "orders") has no effect. In other words, HasChages stays false even after you call Merge on the dataset and thus, the dataset appears as if no changes were made to it. When da.Update(ds1, "orders") is called, the HasChanges property is inspected and found to be false and no changes are committed to the database.

I was trying to see if there was some property of the dataset that you could set to force it to save the data in its tables even when HasChanges is false, but found none.

I'm not sure how you would accomplish what you want in this case. The only way I can think of trasnfering data from one table to another is to do it in a row by row + column by column basis (probably using pure SQL). Of course, this is probably not the best solution but it's the only one I can think of, since adding a new row to a data table requires the use of the NewRow method, which prevents you from simply copying DataRow objects from one DataTable to another.

JC

Friends are angels who lift us to our feet when our wings have trouble remembering how to fly...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top