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

how to update a row in data grid ??

Scheduled Pinned Locked Moved C#
databasecsstestingbeta-testinghelp
5 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 sql database 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 !!

    H 1 Reply Last reply
    0
    • R rocky811

      I am trying to update row in sql database 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 !!

      H Offline
      H Offline
      half life
      wrote on last edited by
      #2

      Why all The mess Why not just using the : SqlDataAdaptor i've been using OdbcDataAdaptor, & OledbDataadaptor and it's easy no 100 Line codes, but half and even less Try it It's actually creates a conector betwen your DB and your Data Grid :)

      Have Fun Never forget it

      R 1 Reply Last reply
      0
      • H half life

        Why all The mess Why not just using the : SqlDataAdaptor i've been using OdbcDataAdaptor, & OledbDataadaptor and it's easy no 100 Line codes, but half and even less Try it It's actually creates a conector betwen your DB and your Data Grid :)

        Have Fun Never forget it

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

        ya i know its really using OledbDataadaptor but my database is not in MS Access but in Sql Server... so everything i need to write is using sql commands .. can u help me with that ?

        H 2 Replies Last reply
        0
        • R rocky811

          ya i know its really using OledbDataadaptor but my database is not in MS Access but in Sql Server... so everything i need to write is using sql commands .. can u help me with that ?

          H Offline
          H Offline
          half life
          wrote on last edited by
          #4

          As i Said Use SqlDataAdapter maybe this will help u :http://www.codeproject.com/csharp/PartialUpdatesFromDataSet.asp[^]

          Have Fun Never forget it

          1 Reply Last reply
          0
          • R rocky811

            ya i know its really using OledbDataadaptor but my database is not in MS Access but in Sql Server... so everything i need to write is using sql commands .. can u help me with that ?

            H Offline
            H Offline
            half life
            wrote on last edited by
            #5

            Here is a Better Article [^] that got all of the connection (Odbc,Oledb,Sql,Oracle) That realy Good :)

            Have Fun Never forget it

            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