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. record no update

record no update

Scheduled Pinned Locked Moved C#
helpannouncement
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
    mjawadkhatri
    wrote on last edited by
    #1

    Hi. i face a problem, record not update and no error show please check my coding and tell me where i do mistake my coding is private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.CommandText = "update contract set suppliername='" + dataGridView1.CurrentRow.Cells[1] + "',buyername='" + dataGridView1.CurrentRow.Cells[2] + "',contract_dt='" + dataGridView1.CurrentRow.Cells[3] + "',delivery='" + dataGridView1.CurrentRow.Cells[4] + "',pmode='" + dataGridView1.CurrentRow.Cells[5] + "',comm='" + dataGridView1.CurrentRow.Cells[6] + "',commper='" + dataGridView1.CurrentRow.Cells[7] + "' where contractid='" + dataGridView1.CurrentRow.Cells[0] + "'"; cmd.Connection = conn; cmd.ExecuteNonQuery(); MessageBox.Show("Record Update.."); conn.Close(); }

    OriginalGriffO G 2 Replies Last reply
    0
    • M mjawadkhatri

      Hi. i face a problem, record not update and no error show please check my coding and tell me where i do mistake my coding is private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.CommandText = "update contract set suppliername='" + dataGridView1.CurrentRow.Cells[1] + "',buyername='" + dataGridView1.CurrentRow.Cells[2] + "',contract_dt='" + dataGridView1.CurrentRow.Cells[3] + "',delivery='" + dataGridView1.CurrentRow.Cells[4] + "',pmode='" + dataGridView1.CurrentRow.Cells[5] + "',comm='" + dataGridView1.CurrentRow.Cells[6] + "',commper='" + dataGridView1.CurrentRow.Cells[7] + "' where contractid='" + dataGridView1.CurrentRow.Cells[0] + "'"; cmd.Connection = conn; cmd.ExecuteNonQuery(); MessageBox.Show("Record Update.."); conn.Close(); }

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      If you are not sure what is going on, then enclose that code in a try...catch block and use

      MessageBox.Show(ex.ToString());

      to find out. It may be that you have a try...catch block outside this method which is catching and discarding the error. On a related note: change this to use parameterized queries, you are leaving yourself wide open to a SQL Injection attack. (Google for "Bobby Tables" to find out what that is) P.S. When you give code fragments, always enclose them in <pre> </pre> blocks with the "code block" widget to preserve the formatting.

      You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • M mjawadkhatri

        Hi. i face a problem, record not update and no error show please check my coding and tell me where i do mistake my coding is private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(); conn.Open(); cmd.CommandText = "update contract set suppliername='" + dataGridView1.CurrentRow.Cells[1] + "',buyername='" + dataGridView1.CurrentRow.Cells[2] + "',contract_dt='" + dataGridView1.CurrentRow.Cells[3] + "',delivery='" + dataGridView1.CurrentRow.Cells[4] + "',pmode='" + dataGridView1.CurrentRow.Cells[5] + "',comm='" + dataGridView1.CurrentRow.Cells[6] + "',commper='" + dataGridView1.CurrentRow.Cells[7] + "' where contractid='" + dataGridView1.CurrentRow.Cells[0] + "'"; cmd.Connection = conn; cmd.ExecuteNonQuery(); MessageBox.Show("Record Update.."); conn.Close(); }

        G Offline
        G Offline
        Greg Chelstowski
        wrote on last edited by
        #3

        The values you try to add to your ugly dynamic SQL are of type DataGridViewCell So first of all, use dataGridView1.CurrentRow.Cells[x].Value to extract the values and as OriginalGriff already said, use parameterized queries. It's easier, more readable, more efficient and NOT UGLY.

        var question = (_2b || !(_2b));

        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