[英]Display a 'string' from 'System.Data.OleDb.OleDbDataReader'. Access Database to C# Form
Trying to display a value from Access Database to display onto ListBox on a form. 试图显示Access数据库中的值以显示在表单上的ListBox上。 The previous form sends this form a string which is 'prevval'- for reference to the code.
先前的表单向该表单发送一个字符串,该字符串为'prevval'-供参考。 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?
QuestionID从技术上讲是一个数字,但是如果我将其作为字符串显示在ListBox上,是否会成为问题?
Error System.Data.OleDb.OleDbException (0x80040E10): No value given for one or more required parameters
错误System.Data.OleDb.OleDbException(0x80040E10):没有为一个或多个必需参数提供值
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());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.