Problem with updating the data grid after editing.
-
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
-
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
-
You mean your database does not update too , or only no change n your datagrid? Mazy No sig. available now.