Hey guys, i dont know if it can be a firebird problem or if am i doing something wrong, but i cant find help anywhere.
The problem is the following.
I m making an application and using data bindings to bind my data to several textboxes, i can navigate through the records without problems, everything seens fine.
Its weird cause i m checking for changes before doing the da.Update(ds) and i have changes in my dataset, but when i execute the DataAdapter.update(DataSet) it gives me this exception:
System.Data.DBConcurrencyException: An attempt to execute an INSERT,
UPDATE, or DELETE statement resulted in zero records affected.
at FirebirdSql.Data.Firebird.FbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
at Sistema.frmBase.GravarDados() in D:\Documents and
Settings\suporte\Meus documentos\Visual Studio
2005\Projects\SGC\Sistema de Gestão Comercial\frmBase.cs:line 122
The weird thing is that it just happens with one field in my DB, and sometimes it works, sometimes dont, i cant find anything in particular that can make this occur, i already checked my update command parameters, already changed the field name, changed the field from INT to VARCHAR, but nothing seens to solve this.
Bellow is my code:
This checks if i have changes in my form, if so it calls the GravarDados() method that will execute the update.
private void btnGravar_Click(object sender, EventArgs e)
{
this.BindingContext[ds, ds.Tables[0].TableName].EndCurrentEdit();
foreach (DataTable dt in ds.Tables)
{
foreach (DataRow dr in dt.Rows)
{
dr.EndEdit();
}
}
if(ds.GetChanges() != null) {
GravarDados();
} else {
MessageBox.Show("Nada para ser gravado!", "Status da gravação:",
MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
This is the function that updates the database, its where i get the exception
protected void GravarDados() {
try
{
da.Update(ds, ds.Tables[0].TableName);
DesabilitarCampos();
MessageBox.Show("Dados gravados corretamente!", "Status da gravação:",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
And here are my commands:
//
// cmdDelete
//
this.cmdDelete.CommandText = "DELETE FROM CLIENTES WHERE CLI_COD = ?";
this.cmdDelete.Parameters.Add
(new FirebirdSql.Data.Firebird.FbParameter("CLI_COD", FirebirdSql.Data.Firebird.FbDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((byte)(0)), ((byte)(0)), "CLI_COD", System.Data.DataRowVersion.Current
, null));
//
// ds
//
//
// cmdInsert
//
this.cmdInsert.CommandText = "INSERT INTO CLIENTES (CLI_NOME ,CLI_SOBRENOME, VED_COD) VALUES (?,?,?)";
this.cmdInsert.Parameters.Add(new FirebirdSql.Data.Firebird.FbParameter("CLI_NOME", FirebirdSql.Data.Firebird.FbDbType.VarChar, 40, "CLI_NOME"));
this.cmdInsert.Parameters.Add
(new FirebirdSql.Data.Firebird.FbParameter("CLI_SOBRENOME", FirebirdSql.Data.Firebird.FbDbType.VarChar, 40, "CLI_SOBRENOME"));
this.cmdInsert.Parameters.Add(new FirebirdSql.Data.Firebird.FbParameter
("VED_COD", FirebirdSql.Data.Firebird.FbDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((byte)(0)), ((byte)(0)), "VED_COD", System.Data.DataRowVersion.Current, null));
//
// cmdSelect
//
this.cmdSelect.CommandText = "SELECT CLI_COD,CLI_NOME,CLI_SOBRENOME, VED_COD FROM CLIENTES";
//
// cmdUpdate
//
this.cmdUpdate.CommandText = "UPDATE CLIENTES SET CLI_NOME=?, CLI_SOBRENOME=?, VED_COD=? WHERE CLI_COD = ?";
this.cmdUpdate.Parameters.Add(new FirebirdSql.Data.Firebird.FbParameter
("CLI_NOME", FirebirdSql.Data.Firebird.FbDbType.VarChar, 40, "CLI_NOME"));
this.cmdUpdate.Parameters.Add(new FirebirdSql.Data.Firebird.FbParameter("CLI_SOBRENOME", FirebirdSql.Data.Firebird.FbDbType.VarChar
, 40, "CLI_SOBRENOME"));
this.cmdUpdate.Parameters.Add(new FirebirdSql.Data.Firebird.FbParameter("CLI_COD", FirebirdSql.Data.Firebird.FbDbType.Integer, 0, System.Data.ParameterDirection.Input
, false, ((byte)(0)), ((byte)(0)), "CLI_COD", System.Data.DataRowVersion.Current, null));
this.cmdUpdate.Parameters.Add(new FirebirdSql.Data.Firebird.FbParameter("VED_COD", FirebirdSql.Data.Firebird.FbDbType.Integer
, 0, System.Data.ParameterDirection.Input, false, ((byte)(0)), ((byte)(0)), "VED_COD", System.Data.DataRowVersion.Current, null));
I Added the commands using the GUI, so i dont know if its right or wrong.
And here are my DataBindings:
private void frmClientes_Load(object sender, EventArgs e)
{
txtCodigo.DataBindings.Add("Text", ds, ds.Tables[0].TableName + ".CLI_COD");
txtNome.DataBindings.Add("Text", ds, ds.Tables[0].TableName + ".CLI_NOME");
txtSobrenome.DataBindings.Add("Text", ds, ds.Tables[0].TableName + ".CLI_SOBRENOME");
txtVendedor.DataBindings.Add("Text", ds, ds.Tables[0].TableName + ".VED_COD");
}
Thanx for any help.
- [Firebird-net-provider] Weird behavior, i cant fig... Fabio Gomes
- Re: [Firebird-net-provider] Weird behavior, i... Carlos Guzmán Álvarez
- Re: [Firebird-net-provider] Weird behavio... Fabio Gomes
- [Firebird-net-provider] Error code -3... Paul Mercea
- Re: [Firebird-net-provider] Error... Carlos Guzmán Álvarez
- RE: [Firebird-net-provider] ... Paul Mercea
- RE: [Firebird-net-provid... Paul Mercea