Durga Velusamy

Durga Velusamy

  • NA
  • 318
  • 115.2k

how to update datatable into sql table using c#

Nov 2 2016 1:54 AM
DataRow dr = dt.Rows.Find(new object[] { custm_id });
if (dr == null)
{
// dt.Rows.Add(dr);
dr = dt.NewRow();
val=true;
dr["custmid"] = custm_id;
}
else
{
dr.BeginEdit();
}
 
dr["fieldname"] = "test";
if (val)
{
dt.Rows.Add(dr);
}
else
{
dr.EndEdit();
}
 
like this i have edited table.
changes affected in datatable  
 
SqlDataAdapter adapter;
using (adapter = new SqlDataAdapter("SELECT  fieldname FROM customlist", con))
 using (new SqlCommandBuilder(adapter))
{
 
 adapter.Update(dt);
  when i try to update
its updatating only new row.  not updating edited rows into sql table.
how is possible any one help 
 
 
 

Answers (2)