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.
Danzz
Posts
-
Problem with updating the data grid after editing. -
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
-
Data type mismatch in criteria expression.ThanX. I solved it by converting with Convert.ToDateTime(). ------------------------------ And of course 2, 3, 4 ... BeeR.
-
Data type mismatch in criteria expression.I would appreciate any help with the following error message. I'm trying to insert records into a ACCESS database. I would like to include a date field to insert query. I tried to convert it with Convert.ToDateTime(myDate) but it doesnt work. Only when i remove the parameters that holds the date value the query is OK. The Date is in good format. When I'm trying to run this query separately in ACCESS it works well. I'm a novice and may b this is boring stuff! ThanX.