HI I am getting the “Concurrency violation the updatecommand affected 0 of the expected 1 records.” error while trying to update a row, weird thing is that I CAN update the row a single time and next time I repeat the process on the same row I get the error, I have already tryed the endinit and endedit thingys, any help would be appreciated!
I am using c# and MySQL innodb
string cs = "server=" + fidaConfig.dtBDConfig.Rows[0][2] + ";user id=root;Password=" + fidaConfig.dtBDConfig.Rows[0][4] + ";persist security info=True;database=facturas";
MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection() { ConnectionString = cs };
switch (tableInvoice)
{
case "factura_idj":
dsLuiscencioTableAdapters.factura_idjTableAdapter idjAdapter = new Control_Administrativo.dsLuiscencioTableAdapters.factura_idjTableAdapter() { Connection = conn };
dsLuiscencio.factura_idjDataTable idj = idjAdapter.GetData();
var facturaidj = (from f in idj where f.no_factura_idj == InvoiceNumber select f).Single();
if (DateTime.Today.Date >= Convert.ToDateTime("01-01-2010") && facturaidj.fecha.Date <= Convert.ToDateTime("01-01-2010"))
{
var quieresactualizar = MessageBox.Show("Desea Actualizar el total de acuerdo a los nuevos impuestos?", "Reforma Fiscal", MessageBoxButtons.YesNo);
if (quieresactualizar == DialogResult.Yes)
{
switch (facturaidj.opt_iva)
{
case 1:
facturaidj.iva = 0;
facturaidj.total = facturaidj.subtotal;
break;
case 2:
facturaidj.iva = facturaidj.subtotal * 0.11;
facturaidj.total = facturaidj.subtotal * 1.11;
break;
case 3:
facturaidj.iva = facturaidj.subtotal * 0.16;
facturaidj.total = facturaidj.subtotal * 1.16;
break;
default:
break;
}
Number2Letter.Number2Letter n2l = new Number2Letter.Number2Letter();
string totalwithnocents = n2l.Numero2Letra(facturaidj.total.ToString(), 0, 0, "peso", "",
Number2Letter.Number2Letter.eSexo.Masculino,
Number2Letter.Number2Letter.eSexo.Masculino).ToUpper();
string strtotalconivaretenido = Math.Round(facturaidj.total, 2, MidpointRounding.ToEven).ToString("###########.00");
string cents = strtotalconivaretenido.Substring(strtotalconivaretenido.IndexOf(".") + 1);
facturaidj.total_letra = string.Format(@"{0} {1}/100 {2}", totalwithnocents, cents, facturaidj.tipo_moneda).ToUpper();
idj.EndInit();
idjAdapter.Update(facturaidj);//this runs only the first time on a row, then throws the error
}
}
break;
continues......
I don’t know if this will have anything to do but:
In addition you have the FLOAT issue mentioned before:
Which can perfectly be extended to double values… the problem seems to be a combination of a incorrect error message when the update tries to find the value to update
Could you try running the update command without actually updating anything? That is, instead of making an actual update, remove all the code except for the Update command so that the factura object is exactly the same and see if that works.