用access数据库string newstye = Convert.ToString(cd.ExecuteScalar());报错
来源:百度知道 编辑:UC知道 时间:2024/05/21 11:38:19
用access数据库string newstye = Convert.ToString(cd.ExecuteScalar());报错标准表达式中数据类型不匹配
异常详细信息: System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配。
源错误:
行 74: cn.Open();
行 75: OleDbCommand cd = new OleDbCommand("select cname from shouruclass where id='" + id + "'", cn);
行 76: string newstye = Convert.ToString(cd.ExecuteScalar());
行 77: if (judge1(newstye))
行 78: {
异常详细信息: System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配。
源错误:
行 74: cn.Open();
行 75: OleDbCommand cd = new OleDbCommand("select cname from shouruclass where id='" + id + "'", cn);
行 76: string newstye = Convert.ToString(cd.ExecuteScalar());
行 77: if (judge1(newstye))
行 78: {
问题都说出来了 标准表达式中数据类型不匹配。
请问楼主表中的数据时什么类型?
你现在的 id='" + id + "'" 对应的表中的数据为string型的
要是你表中数据int型的话 请改成id=" + id + "
vs报的错误一般都是比较准确的,以后请自己好好地对照错误检查一下
把id两边的单引号去掉试试
OleDbCommand cd = new OleDbCommand("select cname from shouruclass where [id]=" + id + "", cn);