filmov
tv
how to insert data in database in asp.net using c# | asp.net save data to database| Asp.Net Tutorial
Показать описание
Example c# code
protected void btnsubmit_Click(object sender, EventArgs e)
{
string fname = txtfname.Text;
string lname = txtlname.Text;
int age = Convert.ToInt32(txtage.Text);
int sal = Convert.ToInt32(txtsalary.Text);
string cs = "data source = .; database = TestDB; Integrated security = true";
SqlConnection con = new SqlConnection(cs);
string query = string.Format("insert into employee values('{0}','{1}',{2},{3})"
,fname,lname,age,sal);
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
ClientScript.RegisterClientScriptBlock(this.GetType(), "K", "swal('God Job','record inserted!...','success')", true);
txtfname.Text = "";
txtlname.Text = "";
txtage.Text = "";
txtsalary.Text = "";
}
Question
how to save data in database using c#
insert data in sql server using c#
Asp.Net Tutorial
Комментарии