how to insert data in database in asp.net using c# | asp.net save data to database| Asp.Net Tutorial

preview_player
Показать описание


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
Комментарии
Автор

bahut gazab .. thank you app pura details mai bataye ho superrr

adminbreakeryt
Автор

Bhai, After insert jo text value humne empty kiya hai.. kya usko koi function likh kar call kar sakte hai kya udhar...

means Clearalltext();

please make video on this to call function and clear value...
or make textbox validation....

Really appreciate your efforts

prashantjoshi
Автор

Sir Please Make Video On CURD operation using Store Procedure

jayeshkalantre