简体   繁体   English

将数据添加到mysql表时获取空白错误异常消息

[英]Getting blank error exception message while adding data to the mysql table

the code below is self explanatory. 下面的代码不言自明。 I have 16 input sources(textboxes , comboboxes,etc) on a form and I want all those inputs to go into a mysql table I created , called submissiontable. 我在表单上有16个输入源(文本框,组合框等),我希望所有这些输入都进入我创建的mysql表中,该表称为Submittingtable。 I have only pasted the parts necessary and not the whole 550 lines of code 我只粘贴了必要的部分,而不粘贴了整个550行代码

public partial class Form1 : System.Windows.Forms.Form
{
     static string conString = "Server=localhost;Database=Work;uid=root;Pwd=password";
     MySqlConnection mson = new MySqlConnection(conString);
     MySqlCommand mcd;
     MySqlDataAdapter adapter;
     MySqlDataReader rdr;
     DataTable dt = new DataTable();

     private void btn_submit_Click(object sender, EventArgs e)
     {
          if (checkBox1.Checked)
          {
               submit(txt_empid.ToString(), txt_empname.ToString(), txt_mgrid.ToString(), txt_mgrname.ToString(), txt_phno.ToString(), txt_emailid.ToString(), txt_dept.ToString(), txt_circle.ToString(), txt_rqst_type.ToString(), txt_pol_period.ToString(), txt_bj.ToString(), txt_chngtype.ToString(), txt_sod.ToString(), txt_destapp.ToString());
          }
          else
                    MessageBox.Show("Agree the terms and conditions");
      }

     //Submit
     private void submit(string empid, string empname, string mgrid, string mgrname, string empph, string empmail, string empdept, string empcircle, string rqsttype, string polperiod, string busjur, string chngtype, string sodno, string destapp )
     {
          //sql stmt

          string submitdb = "INSERT INTO submissiontable(empid,empname,mgrid,mgrname,empph,empmail,empdept,empcirlce,rqsttype,polperiod,buisinessjuris,chngtype,sodno,destapp) VALUES(@eid,@enam,@mgid,@mgnam,@ephone,@email,@edept,@ecirc,@reqtyp,@polprd,@busjur,@chtype,@sodno,@dapp)";
          mcd = new MySqlCommand(submitdb, mson);
                 mcd.Parameters.AddWithValue("@eid", empid);
                 mcd.Parameters.AddWithValue("@enam", empname);
                 mcd.Parameters.AddWithValue("@mgid", mgrid);
                 mcd.Parameters.AddWithValue("@mgnam", mgrname);
                 mcd.Parameters.AddWithValue("@ephone", empph);
                 mcd.Parameters.AddWithValue("@email", empmail);
                 mcd.Parameters.AddWithValue("@edept", empdept);
                 mcd.Parameters.AddWithValue("@ecirc", empcircle);
                 mcd.Parameters.AddWithValue("@reqtyp", rqsttype);
                 mcd.Parameters.AddWithValue("@polprd", polperiod);
                 mcd.Parameters.AddWithValue("@busjur", busjur);
                 mcd.Parameters.AddWithValue("@chtype", chngtype);
                 mcd.Parameters.AddWithValue("@sodno", sodno);
                 mcd.Parameters.AddWithValue("@dapp", destapp);
          //OPEN MSON[CON] AND EXEC INSERT
          try
          {
                mson.Open();
                if (mcd.ExecuteNonQuery() > 0)
                {

                        MessageBox.Show("Submitted Successfully");
                }
                mson.Close();
          }
          catch (Exception ex)
          {
                    MessageBox.Show(ex.Message);
                    MessageBox.Show("test");
                    mson.Close();
          }
      }

screenshot of db: db的屏幕截图: 在此处输入图片说明 在此处输入图片说明 Create query , as requested : 根据要求创建查询:

CREATE TABLE `submissiontable` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `empid` varchar(20) DEFAULT NULL,
  `empname` varchar(20) DEFAULT NULL,
  `mgrid` varchar(20) DEFAULT NULL,
  `mgrname` varchar(20) DEFAULT NULL,
  `empph` varchar(20) DEFAULT NULL,
  `empmail` varchar(20) DEFAULT NULL,
  `empdept` varchar(20) DEFAULT NULL,
  `empcircle` varchar(20) DEFAULT NULL,
  `rqsttype` varchar(20) DEFAULT NULL,
  `polperiod` varchar(20) DEFAULT NULL,
  `buisinessjuris` varchar(50) DEFAULT NULL,
  `chngtype` varchar(20) DEFAULT NULL,
  `sodno` varchar(20) DEFAULT NULL,
  `destapp` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),

) ENGINE=InnoDB DEFAULT CHARSET=utf8

Why does the insert operation not work? 为什么插入操作不起作用? I placed a messagebox in the catch section to confirm that the error is in the try section [as a messagebox with test popped up] 我在catch区域中放置了一个消息框,以确认错误在try部分中([弹出带有测试的消息框])

Well, MySQL error 1054 stands for unknown column. 好吧,MySQL错误1054代表未知列。 It means that in your insert statement you used a column name that does not exists in your table. 这意味着在您的插入语句中,您使用了表中不存在的列名。 The error message itself will tell you more details about which column name may cause the error. 错误消息本身将告诉您有关哪个列名称可能导致错误的更多详细信息。 Interpret the error message and fix the column name issue. 解释错误消息并解决列名问题。

Based on spelling, I think buisinessjuris is a good candidate for a typo issue. 根据拼写,我认为buisinessjuris是错别字问题的不错选择。

The error 1054 for sql is basically unknown column . sql的错误1054基本上是未知列。 So kindly check if all the columns mentioned in your INSERT query are also there in your table "submissiontable". 因此,请检查INSERT查询中提到的所有列是否也都在表“ submissiontable”中。

If they are there kindly get back to me with the create query of your table . 如果它们在那里,请通过您的表的create查询与我联系。

Thank you 谢谢

Thankyou for posting your db 感谢您发布数据库

if the id column in your db is not auto generated ..you will have to specify its value in the insert query as it cannot be null according to your db 如果数据库中的id列不是自动生成的..您将必须在插入查询中指定其值,因为根据您的数据库,它不能为null

Column name empcircle is different in insert query .. change it from empcirlce to empcircle 列名empcircle在插入查询中是不同的..将其从empcirlce更改为empcircle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 向数据表添加新行时出现错误 - While Adding new row to Data Table getting an Error 向Silverlight图表添加数据时出错? - Getting error while adding data to Silverlight charts? 实体框架:在 MySQL 表中插入行时出现异常 - Entity Framework: Getting exception while inserting row in MySQL Table 从表中读取数据时出现错误 - Getting Error while read the data from table 网格视图添加动态行,但插入时获取空值 - grid view to adding row dynamicaly, but getting blank value while inserting 将数据插入表“无法更新实体集”时出错 - Getting error while inserting the data into table "Unable to update the EntitySet " 将数据添加到数据库时发生异常-将int转换为数字数据类型时发生溢出错误 - Exception while adding data to to the database -overflow error converting int to data type numeric wpf:在工具箱中添加“ CrystalReportsViewer”控件时出现异常 - wpf: getting exception while adding “CrystalReportsViewer” control from Toolbox 当我尝试更新表时从数据库中获取错误消息 - Getting error message from data base when I try to update the table 将数据表中的数据放入图表时出现此错误 - I am getting this error while placing data from data table into chart
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM