none
How to update a datarow in dataset in c#? RRS feed

  • Question

  • Hi

    I have a dataset which retrieve data from multiple tables. I want to update one row in the dataset with another row, is it possible?

    Part of my code:

    Foreach(DataRow dr in MyDataSet.Table[0].Rows)

    {

    dr["column1"]=dr["column2"];  //update value from column 2 to column 1

    }

    But it won't work. Another option is to use stored procedure to update, can I update statement which involve joined multiple tables?

    It is quite urgent, many thanks for your help.

    Rainbow

    • Moved by Bob Beauchemin Thursday, July 14, 2011 7:24 PM Moved to a more relevent forum (From:.NET Framework inside SQL Server)
    Thursday, July 14, 2011 10:45 AM

Answers

  • Hi Rainbow;

    Not a problem, glad I was able to help in solving your issue.

    Please take a moment to mark the post as "the answer" to your question and also please Vote As Helpful by clicking the up arrow if it was also helpful to you.

    Thank you and have a great day.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Rainbow88 Friday, July 15, 2011 1:55 PM
    Friday, July 15, 2011 1:29 PM

All replies

  • Hi Rainbow;

    Once you have gone throw updating the rows of the data table you need to instruct the DataAdapter to update the database by executing the following command where adapter is the instance name of the DataAdapter:

    adapter.Update(MyDataSet);

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, July 15, 2011 2:58 AM
  • Hi Fernando

    Many thanks for your kind help. You are right to use DataAdapter for updating.

    Kind regards

    Rainbow

    Friday, July 15, 2011 12:06 PM
  • Hi Rainbow;

    Not a problem, glad I was able to help in solving your issue.

    Please take a moment to mark the post as "the answer" to your question and also please Vote As Helpful by clicking the up arrow if it was also helpful to you.

    Thank you and have a great day.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Rainbow88 Friday, July 15, 2011 1:55 PM
    Friday, July 15, 2011 1:29 PM