试图显示Access数据库中的值,以显示在表单的ListBox上。上一个表单向此表单发送一个字符串"preval",用于引用代码。不完全确定问题是什么?请帮忙!!从技术上讲,QuestionID是一个数字,但如果我把它作为字符串,因为它出现在ListBox上,这是一个问题吗?
错误System.Data.OleDb.OleDbException(0x80040E10):未给定值对于一个或多个所需参数
代码:
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "SELECT QuestionID FROM tblQuestions WHERE (Topic='" + prevval + "')";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
listQuestions.Items.Add(reader.ToString());
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
}
试试这个
listQuestions.Items.Add(reader["QuestionID"].ToString());