SQLCommandBuilder in C#

Published: 19 January 2020
on channel: timeoutexpired
433
1

protected void Page_Load(object sender, EventArgs e)
{
//SQL server connection string using Windows Authentication (without username & password)
string conn1str = @"Data Source=.\SQLEXPRESS;Initial Catalog=TempSample;Trusted_Connection=True;";
SqlConnection con1 = new SqlConnection(conn1str);//Create a connection object
con1.Open();

string strsql = " select emplid,emplname,empldate from table_1 ";
SqlCommand cmd1 = new SqlCommand(strsql, con1);

SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
SqlCommandBuilder cmdbuild = new SqlCommandBuilder(da1); //Create a command builder object

DataSet ds1 = new DataSet(); //Create a dataset object
da1.Fill(ds1);

//Add a new row Start
DataRow row = ds1.Tables[0].NewRow();
row["emplid"] = "7";
row["emplname"] = "fff";
row["empldate"] = System.DateTime.Now.ToString("yyyy/MM/dd");
ds1.Tables[0].Rows.Add(row);
//Add a new row End

da1.Update(ds1); //update data adapter, here your data will insert

con1.Close();

}


On this page of the site you can watch the video online SQLCommandBuilder in C# with a duration of hours minute second in good quality, which was uploaded by the user timeoutexpired 19 January 2020, share the link with friends and acquaintances, this video has already been watched 433 times on youtube and it was liked by 1 viewers. Enjoy your viewing!