2
Reply

how to update datatable into sql table using c#

Durga Velusamy

Durga Velusamy

Nov 2 2016 1:54 AM
216
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)