将记录插入到msaccess数据库中,但显示查询值和目标字段的错误号不相同 [英] insertin the record in to msaccess database but show the error number of query values and destination fields are not the same

查看:48
本文介绍了将记录插入到msaccess数据库中,但显示查询值和目标字段的错误号不相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全球功能代码如下;



Global Function code as follows;

   private Globalfunction GFun = new Globalfunction();
        private string sql;
        private OleDbDataReader oledr;


 public void BindAccessConn()
          {
              OleDbcon = new OleDbConnection();
              OleDbcon.ConnectionString = Accessconncetionstring;
              OleDbcon.Open();
          }

          public void InsertAccessData(string SQL)
          {
              try
              {
                  BindAccessConn();
                  oledbCmd = new OleDbCommand(SQL, OleDbcon);
                  oledbCmd.ExecuteReader();
              }
              catch (Exception e1)
              {
                  error = e1.Message.ToString();
              }

          }




save page code as follows;


 public OleDbConnection OleDbcon = null;
          private string Accessconncetionstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= Data\\HIMT Matrix.mdb;";
          private OleDbCommand oledbCmd;
          private OleDbDataReader Oledbdr;
          public string error;
 

 sql = "insert into Tb_Faculty_Details ([FacCode], [FacName],[Allochrs]) " + " values('" + txt_Faccode.ToString() + "','" + Txt_Facname.ToString() + "', " + txt_Hrs.ToString() + ")";
            try
            {
                GFun.error = "";
                GFun.InsertAccessData(sql);
                if (GFun.error.ToString() != "")
                {
                    MessageBox.Show(GFun.error.ToString(), "Error");
                    return;
                }

                GFun.OleDbcon.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }





在运行模式下输出如下:







In run mode output as followsl


Faculty code    Gs
Faculty Name    G Sekar
Allocated Hrs    10



<当我点击保存按钮错误时显示如下;



查询值和目标字段的数量不一样。显示消息。





三个字段正在插入该查询中我正确编写但显示消息,为什么。



请帮帮我。



我的保存按钮代码是什么错误。



when i click the save button error shows as follows;

number of query values and destination fields are not the same. shows the message.


three fields are inserting in that query i correctly written but shows the message, why.

please help me.

from my save button code what is the mistake.

推荐答案

在插入查询中传递值时,它只有[FacCode],[FacName],[Allochrs]有3个值



调试代码并检查以下行后的价值

sql 变量...

when passing values in insert query check it have 3 values only for [FacCode], [FacName],[Allochrs]

debug code and check value of
sql variable after below line...
sql = "insert into Tb_Faculty_Details ([FacCode], [FacName],[Allochrs]) " + " values(''" + txt_Faccode.ToString() + "'',''" + Txt_Facname.ToString() + "'', " + txt_Hrs.ToString() + ")";



快乐编码!

:)


Happy Coding!
:)


这篇关于将记录插入到msaccess数据库中,但显示查询值和目标字段的错误号不相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆