how acceptchanges works in C#

Posted by Dipu710646 under C# on 1/20/2011 | Points: 10 | Views : 14244 | Status : [Member] | Replies : 5
Hi All,

If dataset works in disconnected architecture, then how dataset.acceptchages updates the databse ?

Any reply is appreciated.

Thanks,
Dipankar




Responses

Posted by: T.saravanan on: 1/20/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Dipankar,

Refer the following link...I think its useful to you..

http://social.msdn.microsoft.com/Forums/en/adodotnetdataset/thread/71a3d1e1-2588-499d-b603-c5c643f6fe50

http://msdn.microsoft.com/en-us/library/system.data.dataset.acceptchanges.aspx

Cheers :)

Thanks,
T.Saravanan

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/20/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Saravanan,

Can you bit explain these articles in simple words about the disconnected architecture and the accept changes.... I cant follow that in the article link provided

Thanks
Karthik
www.f5Debug.net

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 1/20/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Ado.net came with a Disconnected architecture , this means that you connect to the server to get data and disconnect after fetching the data. So lets say i need Customer Data and put it in a Datatable(Disconnected Object) and work with the Data , when done working with the Data, i will need to check if there are changes made via code, if there are changes made , you can use the Adapter object to update the Database using the Update function that will accept your datatable or dataset.


Thank you for posting at Dotnetfunda
[Administrator]

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 1/20/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Karthik,

If using AcceptChanges method in DataTable (or) Dataset, data only updated but its not reflect in database.For update the database from DataTable (or) DataSet we can use the Update method in DataAdapter.

For Ex:

SqlConnection conn =new SqlConnection(......);
SqlDataAdapter da = new SqlDataAdapter("select ID,Name from table",conn);
SqlCommandBuilder cmd =new SqlCommandBuilder(da);
DataTable dtData = new DataTable();
da.Fill(dtData);
DataRow dr = dtData.NewRow();
dr[0] = 4;
dr[1] = "Karthik";
dtData.Rows.Add(dr);
dtData.AcceptChanges(); // done in front end not affected the database
da.Update(dt); // Its also update in database.





Thanks,
T.Saravanan

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/21/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Thanks all!!!

Thanks
Karthik
www.f5Debug.net

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response