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. Web Development
  3. ASP.NET
  4. problem with updating records from datagrid

problem with updating records from datagrid

Scheduled Pinned Locked Moved ASP.NET
helpcomquestionannouncement
4 Posts 4 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.
  • O Offline
    O Offline
    ooooooooppppppss
    wrote on last edited by
    #1

    i m editing records through datagrid..behind my update button i've written following code.. String str = " "; for (int i = 0; i == editgrid.RowCount - 1; i++) { str = "UPDATE criminal SET cr_id = " + editgrid.Rows[i].Cells[1].Value + ", cr_name= '" + editgrid.Rows[i].Cells[2].Value + "', cr_desc='" + editgrid.Rows[i].Cells[3].Value + "' ,cr_pic= '" + editgrid.Rows[i].Cells[4].Value + "', no_times ='" + editgrid.Rows[i].Cells[5].Value + "' WHERE cr_id = " + editgrid.Rows[i].Cells[1].Value; SqlCommand com = new SqlCommand(str, conn); com.ExecuteNonQuery(); label2.Visible = true; } it is not giving any errors but records are not updated,yet can anybody help me??

    software student

    N K J 3 Replies Last reply
    0
    • O ooooooooppppppss

      i m editing records through datagrid..behind my update button i've written following code.. String str = " "; for (int i = 0; i == editgrid.RowCount - 1; i++) { str = "UPDATE criminal SET cr_id = " + editgrid.Rows[i].Cells[1].Value + ", cr_name= '" + editgrid.Rows[i].Cells[2].Value + "', cr_desc='" + editgrid.Rows[i].Cells[3].Value + "' ,cr_pic= '" + editgrid.Rows[i].Cells[4].Value + "', no_times ='" + editgrid.Rows[i].Cells[5].Value + "' WHERE cr_id = " + editgrid.Rows[i].Cells[1].Value; SqlCommand com = new SqlCommand(str, conn); com.ExecuteNonQuery(); label2.Visible = true; } it is not giving any errors but records are not updated,yet can anybody help me??

      software student

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Print your query somewhere and execute it directly in query analyzer. You can find out what is wrong with query.


      My Website | Ask smart questions

      1 Reply Last reply
      0
      • O ooooooooppppppss

        i m editing records through datagrid..behind my update button i've written following code.. String str = " "; for (int i = 0; i == editgrid.RowCount - 1; i++) { str = "UPDATE criminal SET cr_id = " + editgrid.Rows[i].Cells[1].Value + ", cr_name= '" + editgrid.Rows[i].Cells[2].Value + "', cr_desc='" + editgrid.Rows[i].Cells[3].Value + "' ,cr_pic= '" + editgrid.Rows[i].Cells[4].Value + "', no_times ='" + editgrid.Rows[i].Cells[5].Value + "' WHERE cr_id = " + editgrid.Rows[i].Cells[1].Value; SqlCommand com = new SqlCommand(str, conn); com.ExecuteNonQuery(); label2.Visible = true; } it is not giving any errors but records are not updated,yet can anybody help me??

        software student

        K Offline
        K Offline
        kubben
        wrote on last edited by
        #3

        Ok, first you are looping through the entire grid and updating every row even if it was not updated. Normally with a datagrid, you have an edit button which puts the row into edit mode. When the row is in edit mode you have a save and cancel button. Then with your save button you run the update for that single row. Now several post will probably follow talking about sql injection attacts. You should use a parameterize query or a stored procedure to do this update. Finally, my best guess to what your update problem is: I would guess this isn't the crid you think it is: editgrid.Rows[i].Cells[1].Value Hope that helps. Ben

        1 Reply Last reply
        0
        • O ooooooooppppppss

          i m editing records through datagrid..behind my update button i've written following code.. String str = " "; for (int i = 0; i == editgrid.RowCount - 1; i++) { str = "UPDATE criminal SET cr_id = " + editgrid.Rows[i].Cells[1].Value + ", cr_name= '" + editgrid.Rows[i].Cells[2].Value + "', cr_desc='" + editgrid.Rows[i].Cells[3].Value + "' ,cr_pic= '" + editgrid.Rows[i].Cells[4].Value + "', no_times ='" + editgrid.Rows[i].Cells[5].Value + "' WHERE cr_id = " + editgrid.Rows[i].Cells[1].Value; SqlCommand com = new SqlCommand(str, conn); com.ExecuteNonQuery(); label2.Visible = true; } it is not giving any errors but records are not updated,yet can anybody help me??

          software student

          J Offline
          J Offline
          jegastar
          wrote on last edited by
          #4

          why you have put double 'equal to' simbol in FOR loop?

          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