我試圖填充一個文本框,使用下面的代碼的名字及姓氏: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