Cosmin 0

Cosmin 0

  • NA
  • 3
  • 0

update of a dataBase table with a dataSet table problem

Jul 18 2006 2:35 PM

My issue is the update of a dataBase table with a dataSet table as a parameter using C#.
Below is the function I used in my code ---> verry simple.

I noticed that in line :updates = da.Update(tmpDS, tableName) ,updates variable is 0 ,so no update possible.
Perhaps this is not the way to do the update.
IF you can help me with some hints , thanks in advance.

public DataSet dsUpdateData(DataSet ds, string tableName, string ConnectionString)
        {
            //use  a Local temporary dataset
            DataSet tmpDS = new DataSet();
            try
            {
                //dataAdapter object
                SqlDataAdapter da = new SqlDataAdapter(SQLQuery + tableName, ConnectionString);
               
                //update dataset with records from DataBase
                int updates = da.Fill(tmpDS,tableName);

                //update tmpDS with the parameter dataset
                foreach (DataRow dataRow in ds.Tables[tableName].Rows)
                {
                    tmpDS.Tables[tableName1].ImportRow(dataRow);
                    tmpDS.Tables[tableName1].AcceptChanges();
                }

                //update the dataBase<<<---- here I get now update
                updates = da.Update(tmpDS, tableName);

                return tmpDS;
            }
            catch (Exception ex)
            {
               Debug.WriteLine(ex.ToString());
            }
        }