Hello Friends
Here i am to tell you how you can update data in SQL Server Database using C# code, also i will tell you how to delete data from your SQL Server Database by using C# Code on Button Click.
First of all i will tell you how to update Data in SQL Database.
Copy the following code and paste on your C#.Net page on update button click event.
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KVQA-002;Initial
Catalog=ERPDB;Integrated Security=true";
SqlCommand
cmd = new SqlCommand();
cmd.CommandText = "update table name set ESRquarter='" +
TextBox1.Text + "',ERSmonth='" +
TextBox2.Text + "',ERSyear='" +
TextBox3.Text + "',ERSsupprecd='"
+ TextBox4.Text + "',ERSsuppaccpt='"
+ TextBox5.Text + "',ERSqtyrating='"
+ TextBox6.Text + "',ERSdelay='" +
TextBox7.Text + "',ERSratingsch='"
+ DropDownList1.Text + "',ERSattitude='"
+ DropDownList2.Text + "',ERSoverallrating='"
+ TextBox10.Text + "',ERSno='" +
TextBox11.Text + "',ERSrev='" +
TextBox12.Text + "',ERSissue='" +
TextBox13.Text + "' where ERSsuppname='"
+ TextBox14.Text + "'";
cmd.Connection = con;
SqlDataAdapter
da = new SqlDataAdapter();
da.UpdateCommand = cmd;
con.Open();
int x;
x = cmd.ExecuteNonQuery();
if (x
> 0)
{
//Response.Write("<Script>alert('Your
Data Update Succesfully!!!!!!!!!')</Script>");
}
}
Note:- Change your database name because without changing database name you wont able to connect your database.
Now How to Delete Data from your SQL Server Database
copy following code and paste in your C#.Net page on Delete Button click event. But dont foget to change database name.
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KVQA-002;Initial
Catalog=ERPDB;Integrated Security=true";
SqlCommand
cmd = new SqlCommand();
cmd.CommandText = "delete from Pur_Eval_Supp_Performance where
ERSsuppname='" + TextBox14.Text +"'";
cmd.Connection = con;
SqlDataAdapter
da = new SqlDataAdapter();
da.UpdateCommand = cmd;
con.Open();
int x;
x = cmd.ExecuteNonQuery();
if (x
> 0)
{
//Response.Write("<Script>alert('Your
Data is Delete Succesfully!!!!!!!!!')</Script>");
}
If you have any query or having any problem using this code please write in comment box i will reply you as soon as possible.
For New Update dont forget to Subscribe my Blog.
No comments:
Post a Comment