Reputation: 84
Okay, so here is the problem, i get a "Data type mismatch in criteria expression." when attempting a certain code to update my access database. the update part is :
<%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();
}%>
I've already ran tests on the mat/nom/adr.. strings to see if they received the correct content and it seems that way...
My database is set as : matricule is AutoIncrement Number, and the rest (nom/adr/..) is Text. Any help please?
Upvotes: 0
Views: 1077
Reputation: 66459
Take a look here:
where matricule='"+int.Parse(mat)+"'";
Evaluates to:
where matricule='5' // just an example
It's probably treating your "5" as a string. Try changing that to:
where matricule="+int.Parse(mat);
It'd also be a good thing to look into parameterizing your query. It's safer and makes the sql statement easier to maintain too.
Upvotes: 2