Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. update statements using classes [modified]

update statements using classes [modified]

Scheduled Pinned Locked Moved C#
sysadminsecurityhelpannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mamphekgo
    wrote on last edited by
    #1

    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

    N M 2 Replies Last reply
    0
    • M Mamphekgo

      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

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M Mamphekgo

        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

        M Offline
        M Offline
        Mairaaj Khan
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups