//save a record in a database using the Update method of SqlDataAdapter using System.Data; using System.Data.SqlClient; class dd { static void Main() { SqlConnection cn=new SqlConnection("server=.;uid=sa;pwd=1234;database=employee"); SqlDataAdapter da=new SqlDataAdapter("select * from emp",cn); DataTable dt=new DataTable(); da.Fill(dt); //emp has 2 columns known as eno and ename. //Initialize the SqlCommandBuilder. SqlCommandBuilder cd=new SqlComandBuilder(da); //create a DataRow DataRow dr=dt.NewRow(); dr["eno"]=100; dr["ename"]="king"; //the row is temporarily saved dt.Rows.Add(dr); //save the Row permanently da.Update(dt); } }
Login to post response