update statements using classes [modified]
-
Hi.i am try to write update statement using classes but it always gives me an error and use this on my form.i did something like this. public class Update { string empname = ""; public Update() { // // TODO: Add constructor logic here // } public void updateEmployee(string empname1) { empname = empname1; SqlConnection conn = new SqlConnection(); conn.ConnectionString = "integrated security=SSPI;initial catalog=Employee;server = za211149;persist security info=False"; conn.Open(); try { SqlCommand UpdateEmp = new SqlCommand(); UpdateEmp.Connection = conn; UpdateEmp.CommandText = "UPDATE jakes"; UpdateEmp.Parameters.Add(new SqlParameter("@empname",System.Data.SqlDbType.VarChar,50,empname)); UpdateEmp.Parameters["@empname"].Value = this.empname.ToString(); if(UpdateEmp.ExecuteNonQuery()==1) { MessageBox.Show("record updated"); } else { MessageBox.Show("record not updated"); } } catch { MessageBox.Show("o a gafa"); } finally { conn.Close(); } } -- modified at 9:03 Wednesday 19th July, 2006
-
Hi.i am try to write update statement using classes but it always gives me an error and use this on my form.i did something like this. public class Update { string empname = ""; public Update() { // // TODO: Add constructor logic here // } public void updateEmployee(string empname1) { empname = empname1; SqlConnection conn = new SqlConnection(); conn.ConnectionString = "integrated security=SSPI;initial catalog=Employee;server = za211149;persist security info=False"; conn.Open(); try { SqlCommand UpdateEmp = new SqlCommand(); UpdateEmp.Connection = conn; UpdateEmp.CommandText = "UPDATE jakes"; UpdateEmp.Parameters.Add(new SqlParameter("@empname",System.Data.SqlDbType.VarChar,50,empname)); UpdateEmp.Parameters["@empname"].Value = this.empname.ToString(); if(UpdateEmp.ExecuteNonQuery()==1) { MessageBox.Show("record updated"); } else { MessageBox.Show("record not updated"); } } catch { MessageBox.Show("o a gafa"); } finally { conn.Close(); } } -- modified at 9:03 Wednesday 19th July, 2006
You don't have a proper UPDATE statement. It should be in the form UPDATE jakes SET [field_name] = @empname Remember to have a where clause also, unless you want all records updated with this value. WHERE id = @id
-
Hi.i am try to write update statement using classes but it always gives me an error and use this on my form.i did something like this. public class Update { string empname = ""; public Update() { // // TODO: Add constructor logic here // } public void updateEmployee(string empname1) { empname = empname1; SqlConnection conn = new SqlConnection(); conn.ConnectionString = "integrated security=SSPI;initial catalog=Employee;server = za211149;persist security info=False"; conn.Open(); try { SqlCommand UpdateEmp = new SqlCommand(); UpdateEmp.Connection = conn; UpdateEmp.CommandText = "UPDATE jakes"; UpdateEmp.Parameters.Add(new SqlParameter("@empname",System.Data.SqlDbType.VarChar,50,empname)); UpdateEmp.Parameters["@empname"].Value = this.empname.ToString(); if(UpdateEmp.ExecuteNonQuery()==1) { MessageBox.Show("record updated"); } else { MessageBox.Show("record not updated"); } } catch { MessageBox.Show("o a gafa"); } finally { conn.Close(); } } -- modified at 9:03 Wednesday 19th July, 2006
Mamphekgo wrote:
UpdateEmp.CommandText = "UPDATE jakes";
if i'm not wrong you are missing the SET keyword. The above mentioned line should be like this:
UpdateEmp.CommandText = " UPDATE jakes SET
Regards. _____________________________ Success is not something to wait for, its something to work for.