Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
my code is

protected void btnupdate_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("update Employee1 set EmployeeName=@PEmployeeId,EmployeeDesignation=@PEmployeeDesignation,EmployeeDOJ=@PEmployeeDOJ,EmployeeSalary=@PEmployeeSalary,EMployeeDepartmentno=@PEmployeeDepartmentno", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@PEmployeeId", TextBox1.Text);
cmd.Parameters.AddWithValue("@PEmployeeName", TextBox2.Text);
cmd.Parameters.AddWithValue("@PEmployeeDesignation", TextBox3.Text);
cmd.Parameters.AddWithValue("@PEmployeeDOJ", TextBox4.Text);
cmd.Parameters.AddWithValue("@PEmployeeSalary", TextBox5.Text);
cmd.Parameters.AddWithValue("@PEmployeeDepartmentno", TextBox6.Text);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
Console.WriteLine("Data Updated");
}
catch (Exception ex)
{

lblmessage.Text = ex.Message;
}
The Records which are in my table all of them are updating when i updating one record form my table
Posted

You have no WHERE in your sql command

http://www.w3schools.com/sql/sql_where.asp[^]
 
Share this answer
 
Comments
raxhemanth 10-Feb-14 8:29am    
thanks that is the problem right thankyou somuch
Because you forgot to add criteria. Add WHERE clause to update particular record.
 
Share this answer
 
Comments
raxhemanth 10-Feb-14 8:30am    
exactly thats what the problem thanks
Hello ,

you have not given any Where condition in your query . hence all rows are updated .

modified query will be like this

update Employee1 set EmployeeName=@PEmployeeId,EmployeeDesignation=@PEmployeeDesignation,EmployeeDOJ=@PEmployeeDOJ,EmployeeSalary=@PEmployeeSalary,EMployeeDepartmentno=@PEmployeeDepartmentno where EmployeeId=@PEmployeeId


thanks
animesh
 
Share this answer
 
When you omit the WHERE clause in DELETE, OR UPDATE, ALL rows in the table will be affected. sql_update[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900