1
I can’t update a table from a database linked to a datagrid. When I change the data in the datagrid cells, although these appear changed during the debug, at the end the table is not updated. Does anyone know what’s missing in the code?
private static OdbcConnection CreateConnection()
{
return new OdbcConnection("driver= {MySQL ODBC 5.1 Driver};server=192.168.20.29; database=yyyy; uid=esta; password=1234; option = 3 ");
}
using (OdbcConnection connection = CreateConnection())
{
string CmdText = "update lojas set Bloqueado =@bloqueador, DataFim = @DataFim, Nome = @Nome where Id =@Id";
OdbcCommand cm = new OdbcCommand(CmdText, connection);
cm.CommandType = CommandType.Text;
connection.Open();
cm.Parameters.AddWithValue("@Id", grid_lic.CurrentRow.Cells[0].Value);
cm.Parameters.AddWithValue("@bloqueador",grid_lic.CurrentRow.Cells[3].Value);
cm.Parameters.AddWithValue("@DataFim",grid_lic.CurrentRow.Cells[4].Value);
cm.Parameters.AddWithValue("@Nome",grid_lic.CurrentRow.Cells[6].Value);
cm.ExecuteNonQuery();
}
See if this helps you.. http://stackoverflow.com/questions/15526067/c-sharp-refresh-datagridview-when-updating-or-inserted-on-another-form
– durtto
Or this http://stackoverflow.com/questions/21299016/how-to-refresh-or-show-immediately-in-datagridview-after-inserting
– durtto
Is that code on a button? If not, where it is fired?
– Jéf Bueno