Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET MySQL
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.
Posted 7-Mar-13 19:03pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check your no. of fields and no. of values. Both fields and values should be equal.
  Permalink  
Comments
Member 8825505 at 8-Mar-13 0:31am
   
i am 99% sure no. of fields and no. of values are same.
phil.o at 8-Mar-13 4:15am
   
Then you have to make that number a hundred percent.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

you are missing to pass the parameter to
 
Heading->@Heding
 

 
this is at here: "Heading",correctedtc,ESR2hr,MPQBC,
you are missing this one
  Permalink  
v2
Comments
Member 8825505 at 8-Mar-13 2:21am
   
thabks for help i have changed query but again it gives same error please help..
str = "INSERT INTO cbc_new(nm,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) VALUES(?nm,?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)";
Member 8825505 at 8-Mar-13 2:37am
   
thanks for helping
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hello first you must check your query properly....
 
Btnm,CT,Ctnm,esr2hrnm for these values you are not pass parameters
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Richard MacCutchan 269
1 Aajmot Sk 252
2 Marcin Kozub 235
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100