I can NOT update the table, have a DBConcurrency exception.
The code I put is a form with a dataGrid filled with the table data of categorias but when I leave the dataGrid to force a DGValidated I always obtain the same exception....
... can anyone help me?
... Thanks in advance
The code I put is a form with a dataGrid filled with the table data of categorias but when I leave the dataGrid to force a DGValidated I always obtain the same exception....
... can anyone help me?
Code:
public class clsFrmClientes : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dG;
private MySqlDataAdapter myAdapter;
private DataTable myData;
public clsFrmClientes()
{
InitializeComponent();
myAdapter = new MySqlDataAdapter();
myData = new DataTable();
MySqlCommand selCommand = new MySqlCommand();
string selSQL;
MySqlCommand updCommand = new MySqlCommand();
string updSQL;
selSQL = "SELECT * FROM plq.categorias";
updSQL = "UPDATE plq.categorias SET categoria = @1, descripcion = @2 WHERE cod = @0";
try {
// Select Command
selCommand.Connection = clsGlobal.dbCon;
selCommand.CommandText = selSQL;
myAdapter.SelectCommand = selCommand;
// Update Command
updCommand.Connection = clsGlobal.dbCon;
updCommand.CommandText = updSQL;
MySqlParameter vParam1 = updCommand.Parameters.Add( "@1", MySqlDbType.VarChar, 1 );
vParam1.SourceColumn = "categoria";
vParam1.SourceVersion = DataRowVersion.Current;
MySqlParameter vParam2 = updCommand.Parameters.Add( "@2", MySqlDbType.VarChar, 100 );
vParam2.SourceVersion = DataRowVersion.Current;
vParam2.SourceColumn = "descripcion";
MySqlParameter vParam3 = updCommand.Parameters.Add( "@0", MySqlDbType.VarChar, 5 );
vParam3.SourceVersion = DataRowVersion.Original;
vParam3.SourceColumn = "cod";
myAdapter.UpdateCommand = updCommand;
myAdapter.Fill(myData);
dG.DataSource = myData;
}
catch ( MySqlException ex )
{
MessageBox.Show( "Hay un error leyendo de la base de datos: " + ex.Message );
}
}
[i]
--> Here comes some Windows Forms Designer code and then...
--> the InitializeComponent() code
[/i]
void DGValidated(object sender, System.EventArgs e)
{
try {
myAdapter.Update( myData );
}
catch (DBConcurrencyException ex)
{
MessageBox.Show( ex.Message );
}
}
}
... Thanks in advance
Last edited by a moderator: