[英]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.