繁体   English   中英

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

[英]Data type mismatch in criteria expression in ASP C# Update Access Database

好的,问题来了,我收到“条件表达式中的数据类型不匹配”。 尝试使用特定代码更新我的访问数据库时。 更新部分是:

<%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。 请问有什么帮助吗?

看看这里:

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

评估为:

where matricule='5'  // just an example

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

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

研究参数化查询也是一件好事。 它更安全,也使 sql 语句更易于维护。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM