本文介绍了列数与第1行的值计数不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用mysql db在c#.net中进行插入查询的代码:

code for the insert query in c#.net with mysql db:

private void btnsave_Click(object sender, EventArgs e)
      {
         string test = "@name,@age,@sex,@refby,@refno,@date,@hemoglobin,@rbc_count,@pcv,@mcv,@mch,@mchc,@rdw,@total_wbc_count,@polymorphs,@lymphocyts,@monocytes,@eosinophils,@Basophils,@Normoblasts,@Lymphoblasts,@Prolymphocytes,@Myeloblasts,@Promyeloblasts,@Myelocytes,@Metamyelocytes,@BandCells,@esr,@Plateletcount,@plateletsmear1,@PlateletSmearFg,@Bloodgroup,@rh,@AEC,@ReticCount,@Sicklingtest_Metabisulphite,@Sicklingtest_dithionite,@FetalHb,@HbA2,@mp1,@ThickThinSmear,@ThickThinSmearFg,@ps_rbcseries,@ps_rbcseriesfg,@ps_wbcseries,@ps_wbcseriesfg,@ps_platelet,@CoombsTest_Direct,@CoombsTest_Indirect,@remarks,@remarksfg,@timeofcollection,@correctedtc,@ESR2hr,@MPQBC,@MPMethod,@Morpho1,@Density1,@Morpho2,@Density2,@Morpho3,@Density3,@Morpho4,@Density4,@Morpho5,@Density5,@Densitynm,@BT,@CT,@Anisocytosis,@Hypochromia,@Microcytosis,@Macrocytosis,@Poikilocytosis,@Polychromesia,@TargetCell,@TearCell,@SickleCell,@PRNFLG,@New1,@New2,@New3,@CorrectedRetic,@Sno,@HBF,@bondtransfusion,@History,@ElectroComments,@ElectroCommentsfg,@RapidCard,@ReportExam,@BloodMp,@blood,@Pfalci,@FalciR,@Pvivex,@PVR,@BYstd,@wbcgraph,@pltgraph,@rbcgraph,@prgid,@ps";
          string[] field = test.Split(',');
          int size = field.Length;
          Control[] formcontrol = new Control[103] { txtname, txtage, txtage, txtref, txtaccno, dtp1, txtheamo, txtrcbcount, txtpcv, txtmcv, txtmch, txtmchc, txtrdw, txtwbc, txtpolymorphs, txtlymp, txtmono, txteosi, txtbaso, txtNormoblasts, txtLymphoblasts, txtProlymphocytes, txtMyeloblasts, txtPromyeloblasts, txtMyelocytes, txtMetamyelocytes, txtband, txtesr, txtplate, txtblank, txtblank, cbbloodgrp, cbrh, txtaec, txtretic, cbsicking1, cbsicking2, txtfetal, txthba, txtthick, txtthick, txtplateletsmearfg, txtrbcseries, txtrbcfg, txtwbc, txtwbcfg, txtplateletson, cbdirect, cbindirect, txtremarks, txtremarkfg, dtptime, txtCorrectedTLC, txtesr2, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtbt, txtct, txtAnisocytosis, txtHypochromia, txtMicrocytosis, txtMacrocytosis, txtPoikilocytosis, txtPolychromesia, txtTargetCell, txtTearCell, txtSickleCell, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank, txtblank };
       str = "INSERT INTO cbc_new(name,age,sex,refby,refno,date,hemoglobin,rbc_count,pcv,mcv,mch,mchc,rdw,total_wbc_count,polymorphs,lymphocyts,monocytes,eosinophils,Basophils,Normoblasts,Lymphoblasts,Prolymphocytes,Myeloblasts,Promyeloblasts,Myelocytes,Metamyelocytes,BandCells,esr,Plateletcount,plateletsmear1,PlateletSmearFg,Bloodgroup,rh,AEC,ReticCount,Sicklingtest_Metabisulphite,Sicklingtest_dithionite,FetalHb,HbA2,mp1,ThickThinSmear,ThickThinSmearFg,ps_rbcseries,ps_rbcseriesfg,ps_wbcseries,ps_wbcseriesfg,ps_platelet,CoombsTest_Direct,CoombsTest_Indirect,remarks,remarksfg,timeofcollection,Heading,correctedtc,ESR2hr,MPQBC,MPMethod,Morpho1,Density1,Morpho2,Density2,Morpho3,Density3,Morpho4,Density4,Morpho5,Density5,Densitynm,BT,Btnm,CT,Ctnm,esr2hrnm,Anisocytosis,Hypochromia,Microcytosis,Macrocytosis,Poikilocytosis,Polychromesia,TargetCell,TearCell,SickleCell,PRNFLG,New1,New2,New3,CorrectedRetic,Sno,HBF,bondtransfusion,History,ElectroComments,ElectroCommentsfg,RapidCard,ReportExam,BloodMp,blood,Pfalci,FalciR,Pvivex,PVR,BYstd,wbcgraph,pltgraph,rbcgraph,prgid,ps) VALUES(@name,@age,@sex,@refby,@refno,@date,@hemoglobin,@rbc_count,@pcv,@mcv,@mch,@mchc,@rdw,@total_wbc_count,@polymorphs,@lymphocyts,@monocytes,@eosinophils,@Basophils,@Normoblasts,@Lymphoblasts,@Prolymphocytes,@Myeloblasts,@Promyeloblasts,@Myelocytes,@Metamyelocytes,@BandCells,@esr,@Plateletcount,@plateletsmear1,@PlateletSmearFg,@Bloodgroup,@rh,@AEC,@ReticCount,@Sicklingtest_Metabisulphite,@Sicklingtest_dithionite,@FetalHb,@HbA2,@mp1,@ThickThinSmear,@ThickThinSmearFg,@ps_rbcseries,@ps_rbcseriesfg,@ps_wbcseries,@ps_wbcseriesfg,@ps_platelet,@CoombsTest_Direct,@CoombsTest_Indirect,@remarks,@remarksfg,@timeofcollection,@correctedtc,@ESR2hr,@MPQBC,@MPMethod,@Morpho1,@Density1,@Morpho2,@Density2,@Morpho3,@Density3,@Morpho4,@Density4,@Morpho5,@Density5,@Densitynm,@BT,@CT,@Anisocytosis,@Hypochromia,@Microcytosis,@Macrocytosis,@Poikilocytosis,@Polychromesia,@TargetCell,@TearCell,@SickleCell,@PRNFLG,@New1,@New2,@New3,@CorrectedRetic,@Sno,@HBF,@bondtransfusion,@History,@ElectroComments,@ElectroCommentsfg,@RapidCard,@ReportExam,@BloodMp,@blood,@Pfalci,@FalciR,@Pvivex,@PVR,@BYstd,@wbcgraph,@pltgraph,@rbcgraph,@prgid,@ps)";
          cmd = new MySqlCommand(str, Classmysql.conmain);
          int i = 0;
          foreach (string w in field)
          {
              cmd.Parameters.AddWithValue(w.Trim(), formcontrol[i].Text);

              i++;
          }
          cmd.ExecuteNonQuery();
          MessageBox.Show("saved");
     }



错误详情:


error details:

MySql.Data.MySqlClient.MySqlException was unhandled
  Message="Column count doesn't match value count at row 1"
  Source="MySql.Data"
  ErrorCode=-2147467259
  Number=1136



请帮忙解决这个问题紧急。

提前谢谢。


please help to resolve this problem its urgent.
thanks in advance.

推荐答案




这篇关于列数与第1行的值计数不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:34