我试图填充一个文本框,使用下面的代码的名字及姓氏:oledbException是未处理的错误appering
using (OleDbConnection connName = new OleDbConnection(strCon))
{
String sqlName = "SELECT forename, Surname FROM customer WHERE [customerID]=" + txtCustomerID.Text;
// Create a command to use to call the database.
OleDbCommand commandname = new OleDbCommand(sqlName, connName);
connName.Open();
// Create a reader containing the results
using (OleDbDataReader readerName = commandname.ExecuteReader())
{
readerName.Read(); // Advance to the first row.
txtName.Text = readerName[0].ToString();
}
connName.Close();
}
不过,我发现了错误:OleDbException
了未处理。
"no required values for one of more required parameters"
在ExecuteReader
我不知道如何去解决这个问题。
编辑:下面的代码几乎是完全相同的查询中的信息栏,但这个例外是不会为它。
string strCon = Properties.Settings.Default.PID2dbConnectionString;
using (OleDbConnection conn = new OleDbConnection(strCon))
{
String sqlPoints = "SELECT points FROM customer WHERE [customerID]=" + txtCustomerID.Text;
conn.Open();
// Create a command to use to call the database.
OleDbCommand command = new OleDbCommand(sqlPoints, conn);
// Create a reader containing the results
using (OleDbDataReader reader = command.ExecuteReader())
{
reader.Read(); // Advance to the first row.
txtPoints.Text = reader[0].ToString(); // Read the contents of the first column
}
conn.Close();
}
是txtCustomerID.text null? – Brian
你调试了你的代码吗?哪条线给你这个错误? –
@SonerGönül - 我相信OP说这是这一行:'使用(OleDbDataReader readerName = commandname.ExecuteReader())' – Brian