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. how to update a row in data grid ?? [modified]

how to update a row in data grid ?? [modified]

Scheduled Pinned Locked Moved ASP.NET
csstestingbeta-testinghelptutorial
6 Posts 2 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.
  • R Offline
    R Offline
    rocky811
    wrote on last edited by
    #1

    i am trying to update row in table (data grid ) but unable to do it .. this is what i have done so far .. protected void UpdateCommand(object source, DataGridCommandEventArgs e) { Response.Write("testing"); SqlConnection conn = new SqlConnection(connectionString); try { conn.Open(); string database1 = "Level1"; TextBox UserName = (TextBox)(e.Item.Cells[2].Controls[0]); TextBox MacAddr = (TextBox)(e.Item.Cells[3].Controls[0]); DataSet ds = new DataSet(); SqlCommand myCommand = new SqlCommand("UPDATE " + database1 + " SET UserName = '" + UserName + "', MacAddr = '" + MacAddr+" ' ", conn); myCommand.Connection = conn; myCommand.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(ex.Message); Response.End(); if (conn != null) conn.Close(); return; } finally { Response.Redirect((string)Session["PreviousURL"]); } conn.Close(); DataGrid1.EditItemIndex = -1; can someone help me how to update after we clik edit button in each textbox in a row ?? Thanx !! -- modified at 11:39 Tuesday 6th November, 2007

    J 1 Reply Last reply
    0
    • R rocky811

      i am trying to update row in table (data grid ) but unable to do it .. this is what i have done so far .. protected void UpdateCommand(object source, DataGridCommandEventArgs e) { Response.Write("testing"); SqlConnection conn = new SqlConnection(connectionString); try { conn.Open(); string database1 = "Level1"; TextBox UserName = (TextBox)(e.Item.Cells[2].Controls[0]); TextBox MacAddr = (TextBox)(e.Item.Cells[3].Controls[0]); DataSet ds = new DataSet(); SqlCommand myCommand = new SqlCommand("UPDATE " + database1 + " SET UserName = '" + UserName + "', MacAddr = '" + MacAddr+" ' ", conn); myCommand.Connection = conn; myCommand.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(ex.Message); Response.End(); if (conn != null) conn.Close(); return; } finally { Response.Redirect((string)Session["PreviousURL"]); } conn.Close(); DataGrid1.EditItemIndex = -1; can someone help me how to update after we clik edit button in each textbox in a row ?? Thanx !! -- modified at 11:39 Tuesday 6th November, 2007

      J Offline
      J Offline
      John ph
      wrote on last edited by
      #2

      rocky811 wrote:

      i am trying to update row in sql database

      rocky811 wrote:

      SqlCommand myCommand = new SqlCommand("UPDATE " + database1 + " SET UserName = '" + UserName + "', MacAddr = '" + MacAddr+" ' ", conn);

      You can't do that unless you understand the Basic's of SQL. I would reccomend you to go through the Basic's Of SQL Commands.[^]

      Regards
       - J O H N -


      R 1 Reply Last reply
      0
      • J John ph

        rocky811 wrote:

        i am trying to update row in sql database

        rocky811 wrote:

        SqlCommand myCommand = new SqlCommand("UPDATE " + database1 + " SET UserName = '" + UserName + "', MacAddr = '" + MacAddr+" ' ", conn);

        You can't do that unless you understand the Basic's of SQL. I would reccomend you to go through the Basic's Of SQL Commands.[^]

        Regards
         - J O H N -


        R Offline
        R Offline
        rocky811
        wrote on last edited by
        #3

        can u help me with the above code please ?

        J 1 Reply Last reply
        0
        • R rocky811

          can u help me with the above code please ?

          J Offline
          J Offline
          John ph
          wrote on last edited by
          #4

          Database doesn't have rows. Only tables in the Database can contain Row's. what is that you are trying to do exactly in that code? I have sent you a link to Read the Basic's of SQL Command. If you go through it you will understand how to write a UPDATE statement in SQL.

          Regards
           - J O H N -


          R 1 Reply Last reply
          0
          • J John ph

            Database doesn't have rows. Only tables in the Database can contain Row's. what is that you are trying to do exactly in that code? I have sent you a link to Read the Basic's of SQL Command. If you go through it you will understand how to write a UPDATE statement in SQL.

            Regards
             - J O H N -


            R Offline
            R Offline
            rocky811
            wrote on last edited by
            #5

            sorry !! i mistyped it !!! i actually wanted to update a row in table.. i have a data grid with few columns in it . I want to edit each row and update it . when i try to click edit button it shows an exception (Invalid Operation) . Hope u got it now..

            J 1 Reply Last reply
            0
            • R rocky811

              sorry !! i mistyped it !!! i actually wanted to update a row in table.. i have a data grid with few columns in it . I want to edit each row and update it . when i try to click edit button it shows an exception (Invalid Operation) . Hope u got it now..

              J Offline
              J Offline
              John ph
              wrote on last edited by
              #6

              Here is the syntax of the UPDATE statement used to make changes to the existing records in table. update tablename set columnname = newvalue [,columnxname = newvaluex...] where columnname OPERATOR value [and|or columnnamex OPERATOR valuex] Compare this syntax with your UPDATE statement and check whether you have given it right.

              Regards
               - J O H N -


              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