2010-01-05 39 views
0

HI我正在收到“并发违反updatecommand影响0期望1记录。”尝试更新一行时发生错误,奇怪的是我可以单次更新该行,并且下一次我在同一行上重复该过程时出现错误,我已经尝试了endinit并结束了其中的任务将不胜感激!第二次更新行的并发错误C#

我使用C#和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...... 
+0

请发送代码 – CSharpAtl 2010-01-05 01:21:36

+0

您使用的是MyISAM还是InnoDB? – CSharpAtl 2010-01-05 01:23:43

+0

在您的表适配器更新后是否有更新行?像触发器一样? – mlsteeves 2010-01-05 01:33:20

回答

1

我不知道这是否会有什么关系,但是:

我finaly发现我的问题,这是 不相关的并发性可言,我已经通过 发现问题在SQL Server数据库上测试相同的 代码,它是 给我另一个错误消息,所以 然后我发现,也许MS Access 错误,他的错误和 问题是别的!

另外你有FLOAT issue之前提到的:??

MySqlCommandBuilder将使用WHERE COL = 1 AND 山坳= 2组成的 UPDATE命令在FLOAT列你会 永远以这种方式找到确切的值。

从而可以完美地扩展到双值......这个问题似乎是一个不正确的错误消息的组合,当更新尝试查找值来更新

你能尝试运行更新命令没有实际更新什么?也就是说,除了进行实际的更新之外,删除除了更新命令以外的所有代码,这样factura对象完全相同,看看是否有效。

+0

LO obscuro德尔asunto ES阙agarro POR decir EL排1个Y LO paso por el codigo y la primera vez sale todo bien,despues al correrlo de nuevo con el renglon 1 sale el error !!! – Luiscencio 2010-01-07 16:06:16

+0

行有没有可能第一次没有改变? – 2010-01-07 16:08:30

+0

nope,我检查和行确实得到更新,实际上没有理由(也没有posibility)通过同一行两次,但错误仍然关注我 – Luiscencio 2010-01-07 16:10:39

0

我不知道,如果你在你的数据库中使用float的数据类型,但这篇文章可能是发生了什么事给你:MySql - Float Issue

+0

我没有使用浮动列,它们都是DOUBLE,谢谢 – Luiscencio 2010-01-05 01:49:12

+2

使用FLOAT/DOUBLE获取货币值是大量错误---由于舍入错误,您会在这里和那里损失/获取资金。你应该使用DECIMAL。 见http://stackoverflow.com/questions/1930247/does-money-map-to-float-well – 2010-01-07 15:51:25

+0

@Alex Brasetvik - 感谢您的意见 – Luiscencio 2010-01-07 16:01:47

0

什么是idjAdapter.Update()后面的SQL,它是如何生成的?你在Visual Studio中使用拖放设计器吗?如果你这样做,那么你会想检查自动生成的更新脚本?在我使用MS SQL世界中的设计器代码的经验中,它经常会包含一个非常复杂的WHERE语句,它只在行的每个旧字段仍然存在时才更新。

如果您的表恰好包含自动生成的时间戳字段或类似内容,那么您可能遇到两个用户遇到的问题,此字段可能会在后面更新,因此更新中的WHERE将失败,导致适配器抛出此并发异常。

然后您需要决定如何处理该问题。如果您只想获得最后一个胜利逻辑,那么您需要手动更改设计器中的更新SQL(从该表适配器的设计器的属性窗口中),以便仅将该表的主键包含在WHERE子句中Update语句。

相关问题