ASP C#更新访问数据库中的条件表达式中的数据类型不匹配

时间:2014-02-01 01:37:44

标签: c# asp.net database access-vba oledb

好的,这就是问题所在,我得到了“条件表达式中的数据类型不匹配”。在尝试某个代码来更新我的访问数据库时。 更新部分是:

<%if (Request.Form["CmdEnregistrer"] != null)
         {
             cnx.Open();
             string sql1;
             string mat;
             string nom;
             string adr;
             string sexe;
             string ema;
             string tel;
             for (int bo = 1; bo < tmp; bo++)
             {

                 mat = Request.Form["matricule"+bo];
                 nom = Request.Form["nom" + bo];
                 adr = Request.Form["adresse" + bo];
                 sexe = Request.Form["sexe" + bo];
                 ema = Request.Form["email" + bo];
                 tel = Request.Form["tel" + bo];
                 sql1 = "Update Enseignant Set nom='"+nom+"',adresse='"+adr+"',sexe='"+sexe+"',email='"+ema+"',tel='"+tel+"' where matricule='"+int.Parse(mat)+"'";
                 OleDbCommand cmd1 = new OleDbCommand(sql1, cnx);
                 cmd1.ExecuteNonQuery();
             } cnx.Close();

}%>

我已经在mat / nom / adr ..字符串上运行测试,看看他们是否收到了正确的内容,看起来就是这样......

我的数据库设置为:matricule是AutoIncrement Number,其余(nom / adr / ..)是Text。 有什么帮助吗?

1 个答案:

答案 0 :(得分:2)

看看这里:

where matricule='"+int.Parse(mat)+"'";

评估为:

where matricule='5'  // just an example

它可能将你的“5”视为一个字符串。尝试将其更改为:

where matricule="+int.Parse(mat);

查看parameterizing您的查询也是一件好事。它更安全,也使sql语句更容易维护。