String start_cd;
String end_cd;
opencon();
SqlCommand res = new SqlCommand("SELECT ID,'" + start_cd + "','" + end_cd + "' FROM Train_route_up WHERE '" + start_cd + "'!=0 or '" + end_cd + "'!=0", con);
SqlDataAdapter sda_res = new SqlDataAdapter(res);
DataTable dt_res = new DataTable();
sda_res.Fill(dt_res);
listBox1.DataSource=dt_res;
listBox1.DisplayMember=" +start_cd+ ";
//Train_route_up= SQL table name
//FOT=start_cd value(nvarchar)
我将其视为错误:将varchar值'FOT'转换为数据类型int时,转换失败。我要去哪里错了?
您的错误是在数据库认为必须将字符串转换为整数时,SQL Server产生的错误。
您在where
子句中有以下表达式:
'" + start_cd + "'!=0 or '" + end_cd + "'!=0
您正在将字符串(单引号)与整数(0)进行显式比较。这是其中一种情况。如果字符串不是数字格式,则将产生错误。
我不知道您要做什么,也许是以下其中一种:
比较字符串 '0'
'" + start_cd + "'!='0' or '" + end_cd + "'!='0'
比较NULL
'" + start_cd + "' is not null or '" + end_cd + "' is not null
请参考列名而不是字符串:
" + start_cd + "!=0 or " + end_cd + "!=0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句