Trying to display a value from Access Database to display onto ListBox on a form. The previous form sends this form a string which is 'prevval'- for reference to the code. Not entirely sure what the issue is? Please Help!! The QuestionID is technically a number but is it an issue if im making it a string because its being presented on the ListBox?
Error System.Data.OleDb.OleDbException (0x80040E10): No value given for one or more required parameters
Code:
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());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.