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. Datagrid Update

Datagrid Update

Scheduled Pinned Locked Moved ASP.NET
databasedesignhelpquestionannouncement
3 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.
  • C Offline
    C Offline
    Commickey
    wrote on last edited by
    #1

    Hello, I am working on a datagrid update... when I click on edit, I can get the textboxes but when I make the changes and click on the update button, I still have the old items in there... .can someone help? here is the code for my update command: string cursusname, niveau, plaats, start, end, dip, finance,pers_id, afdeling, cursusID; cursusname = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[5].Controls[0]).Text; niveau= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[6].Controls[0]).Text; plaats= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[7].Controls[0]).Text; start = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[8].Controls[0]).Text; end= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[9].Controls[0]).Text; dip = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[10].Controls[0]).Text; finance= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[11].Controls[0]).Text; pers_id= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[0].Controls[0]).Text; afdeling= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[1].Controls[0]).Text; cursusID= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[4].Controls[0]).Text; System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection("Provider=sqloledb;Data Source=SQL_SERVER;Initial Catalog=Intra_STUDENT;User Id=student;Password=student"); string sql = "UPDATE P_Cursus SET " + "CursusNaam='"+cursusname+"', " + "Niveau="+niveau+", "+ "Plaats='"+plaats+"',"+ "StartDatum='" + start + "',"+ "EindDatum='" + end + "', "+ "Diploma='" + dip + "', "+ "Financiering='"+finance+"' WHERE personeel_id="+pers_id+" AND Personeel_filliaal_afdeling ="+afdeling+" AND cursus_id = "+cursusID+""; System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(sql,conn); myCommand.CommandType = CommandType.Text; conn.Open(); myCommand.ExecuteNonQuery(); conn.Close(); DataGrid1.EditItemIndex = -1; DataGrid1.DataBind();

    P 1 Reply Last reply
    0
    • C Commickey

      Hello, I am working on a datagrid update... when I click on edit, I can get the textboxes but when I make the changes and click on the update button, I still have the old items in there... .can someone help? here is the code for my update command: string cursusname, niveau, plaats, start, end, dip, finance,pers_id, afdeling, cursusID; cursusname = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[5].Controls[0]).Text; niveau= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[6].Controls[0]).Text; plaats= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[7].Controls[0]).Text; start = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[8].Controls[0]).Text; end= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[9].Controls[0]).Text; dip = ((System.Web.UI.WebControls.TextBox)e.Item.Cells[10].Controls[0]).Text; finance= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[11].Controls[0]).Text; pers_id= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[0].Controls[0]).Text; afdeling= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[1].Controls[0]).Text; cursusID= ((System.Web.UI.WebControls.TextBox)e.Item.Cells[4].Controls[0]).Text; System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection("Provider=sqloledb;Data Source=SQL_SERVER;Initial Catalog=Intra_STUDENT;User Id=student;Password=student"); string sql = "UPDATE P_Cursus SET " + "CursusNaam='"+cursusname+"', " + "Niveau="+niveau+", "+ "Plaats='"+plaats+"',"+ "StartDatum='" + start + "',"+ "EindDatum='" + end + "', "+ "Diploma='" + dip + "', "+ "Financiering='"+finance+"' WHERE personeel_id="+pers_id+" AND Personeel_filliaal_afdeling ="+afdeling+" AND cursus_id = "+cursusID+""; System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(sql,conn); myCommand.CommandType = CommandType.Text; conn.Open(); myCommand.ExecuteNonQuery(); conn.Close(); DataGrid1.EditItemIndex = -1; DataGrid1.DataBind();

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      It's because you're not resetting the datasource of the gridview to the new updated dataset before binding.

      C 1 Reply Last reply
      0
      • P Paddy Boyd

        It's because you're not resetting the datasource of the gridview to the new updated dataset before binding.

        C Offline
        C Offline
        Commickey
        wrote on last edited by
        #3

        Thanks alot... now it works..... but my problem is now with the delete function... it is a kind of trickey... it not firing...

        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