【发布时间】:2013-12-23 10:16:10
【问题描述】:
这是我的代码:
OleDbCommand Cmd = new OleDbCommand();
Cmd.Connection = MyConn;
Cmd.CommandText = "SELECT * FROM catalogue WHERE id = '" + questionid + "'";
OleDbDataReader read = Cmd.ExecuteReader();
int id = 0;
while (read.Read())
{
id = Convert.ToInt32(read["id"]);
}
这是它给我的错误:
Line 27: Cmd.CommandText = "SELECT * FROM catalogue WHERE id = '" + questionid + "'";
Line 28:
Line 29: OleDbDataReader read = Cmd.ExecuteReader(); // The error is here
Line 30:
Line 31: int id = 0;
我知道 Stack Overflow 上也有 another question about the same issue,但它似乎没有解决我的问题(它可能会解决你的问题,所以我放了一个链接)。
【问题讨论】:
-
你能指出它在哪一行抛出异常吗?代码似乎没问题。
-
是
questionid和id在catalogue是相同/等效的数据类型。如果是这样,请确保 questionid 不为空。 @nvoigt 的观点很好,你应该使用参数
标签: c# sql .net ms-access oledb