Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
QtN:Iam geting the data from database and store table data in dataset table .
I modified few rows in dataset table now i want update only modified rows into database


Please send code for this


Regards


venkat
Posted

1 solution

public int Update(DataSet ds)
        {
            try
            {
                SqlConnection cnn = new SqlConnection("Connection string here");
                SqlDataAdapter da = new SqlDataAdapter("Select command here", cnn);
                SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(da);

                cnn.Open();
                da.Update(ds);
            }
            catch
            {
                return -1;
            }
            finally
            {
                if(cnn!=null && cnn.State == ConnectionState.Open){
                    cnn.Close();
                }
            }

            return 1;
        }


You can change parameter DataSet to DataRow[] if you already get modified rows
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900