开发者

Datatype mismatch in query expression with OleDbCommand

char zoneCH = '-'; 
string insertString = "UPD开发者_StackOverflow中文版ATE streets set TmpColumn=City+'" + zoneCH + "'+State+'" +zoneCH +"'+Zip WHERE 1"; 
OleDbCommand com1 = new OleDbCommand(insertString, mdbConnection);
com1.ExecuteNonQuery();

This will work if Zip is a string, but if Zip is a Number I get a data type mismatch in query expression. How can I make it work with a Number?


Probably because it's trying to Add instead of concatenate. Different DB's handle this differently. Some use the left side to determine what it should do.

You should explicitly cast the Zip to a string and then you'll be fine

However since this is MS Access the best bet is to use the & to concatenate

string insertString = "UPDATE streets set TmpColumn=City & '" + zoneCH + "'& State &'" +zoneCH +"'& Zip WHERE 1"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜