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 the data grid after editing.

Problem with updating the data grid after editing.

Scheduled Pinned Locked Moved ASP.NET
csharphelpcssdatabasevisual-studio
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.
  • D Offline
    D Offline
    Danzz
    wrote on last edited by
    #1

    HI I'm working on webApp [vs .net 2002, c#, Access 2002] I created some form that includes the ediable data grid like in web matrix template The delete, cancel, add new commands are OK, but when I'm trying to update the data grid after editing some row nothing is happen. Even some little eXception ;) I would appreciate any help. Here is the code of DataGrid_Update: public void DataGrid_Update(object sender, DataGridCommandEventArgs e) { // update the database with the new values // get the edit text boxes string strPictureID = ((TextBox)e.Item.Cells[2].Controls[0]).Text;//need to convert to int string strFilename = ((TextBox)e.Item.Cells[3].Controls[0]).Text; string strQuantity = ((TextBox)e.Item.Cells[4].Controls[0]).Text;//need to convert to int string strServiceName = ((TextBox)e.Item.Cells[5].Controls[0]).Text; // TODO: update the Command value for your application System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(GetConnectionString()); System.Data.OleDb.OleDbCommand UpdateCommand = new System.Data.OleDb.OleDbCommand(); UpdateCommand.Connection = myConnection; if (AddingNew) UpdateCommand.CommandText = "INSERT INTO t_Basket(PictureID, Filename, Quantity, ServiceName) VALUES (@PictureID, @Filename, @Quantity, @ServiceName)"; else { UpdateCommand.CommandText = "UPDATE t_Basket SET Filename = @Filename, Quantity = @Quantity, ServiceName = @ServiceName WHERE PictureID = @PictureID"; UpdateCommand.Parameters.Add("@PictureID", System.Data.OleDb.OleDbType.VarChar,255).Value = strPictureID; UpdateCommand.Parameters.Add("@Filename", System.Data.OleDb.OleDbType.VarChar, 50).Value = strFilename; UpdateCommand.Parameters.Add("@Quantity", System.Data.OleDb.OleDbType.VarChar, 50).Value = strQuantity; UpdateCommand.Parameters.Add("@ServiceName", System.Data.OleDb.OleDbType.VarChar, 50).Value = strServiceName; } // execute the command try { int rowsAffected = 0; myConnection.Open(); rowsAffected = UpdateCommand.ExecuteNonQuery(); Message.Text = rowsAffected.ToString(); } catch (Exception ex) { Message.Text = ex.ToString(); } finally { myConnection.Close(); } // Resort the grid for new records if (AddingNew) { DataGrid1.CurrentPageIndex = 0; AddingNew = false; } // rebind the grid DataGrid1.EditItemIndex = -1; BindGrid(); } I hope that isn't too boring stuf

    M 1 Reply Last reply
    0
    • D Danzz

      HI I'm working on webApp [vs .net 2002, c#, Access 2002] I created some form that includes the ediable data grid like in web matrix template The delete, cancel, add new commands are OK, but when I'm trying to update the data grid after editing some row nothing is happen. Even some little eXception ;) I would appreciate any help. Here is the code of DataGrid_Update: public void DataGrid_Update(object sender, DataGridCommandEventArgs e) { // update the database with the new values // get the edit text boxes string strPictureID = ((TextBox)e.Item.Cells[2].Controls[0]).Text;//need to convert to int string strFilename = ((TextBox)e.Item.Cells[3].Controls[0]).Text; string strQuantity = ((TextBox)e.Item.Cells[4].Controls[0]).Text;//need to convert to int string strServiceName = ((TextBox)e.Item.Cells[5].Controls[0]).Text; // TODO: update the Command value for your application System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(GetConnectionString()); System.Data.OleDb.OleDbCommand UpdateCommand = new System.Data.OleDb.OleDbCommand(); UpdateCommand.Connection = myConnection; if (AddingNew) UpdateCommand.CommandText = "INSERT INTO t_Basket(PictureID, Filename, Quantity, ServiceName) VALUES (@PictureID, @Filename, @Quantity, @ServiceName)"; else { UpdateCommand.CommandText = "UPDATE t_Basket SET Filename = @Filename, Quantity = @Quantity, ServiceName = @ServiceName WHERE PictureID = @PictureID"; UpdateCommand.Parameters.Add("@PictureID", System.Data.OleDb.OleDbType.VarChar,255).Value = strPictureID; UpdateCommand.Parameters.Add("@Filename", System.Data.OleDb.OleDbType.VarChar, 50).Value = strFilename; UpdateCommand.Parameters.Add("@Quantity", System.Data.OleDb.OleDbType.VarChar, 50).Value = strQuantity; UpdateCommand.Parameters.Add("@ServiceName", System.Data.OleDb.OleDbType.VarChar, 50).Value = strServiceName; } // execute the command try { int rowsAffected = 0; myConnection.Open(); rowsAffected = UpdateCommand.ExecuteNonQuery(); Message.Text = rowsAffected.ToString(); } catch (Exception ex) { Message.Text = ex.ToString(); } finally { myConnection.Close(); } // Resort the grid for new records if (AddingNew) { DataGrid1.CurrentPageIndex = 0; AddingNew = false; } // rebind the grid DataGrid1.EditItemIndex = -1; BindGrid(); } I hope that isn't too boring stuf

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      You mean your database does not update too , or only no change n your datagrid? Mazy No sig. available now.

      D 1 Reply Last reply
      0
      • M Mazdak

        You mean your database does not update too , or only no change n your datagrid? Mazy No sig. available now.

        D Offline
        D Offline
        Danzz
        wrote on last edited by
        #3

        Hi Mazy. ThanX for reply. When I'm trying to edit an existing row there are NO changes in both cases DataGrid and DB. The strangest thing is the fact that after adding a new row to data grid there is changes in DB and also in data grid. GreetingS. Danzz.

        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