2010-01-05 37 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語句。

相關問題