我正在尝试使用OleDbDataReader,但它返回此错误:
No data exists for the row column
我正在使用访问数据库。任何人都可以帮助我确定此错误的来源吗?这是我的代码:
private void UpdateStudent_Load(object sender, EventArgs e)
{
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = new OleDbCommand(
"select * from Students where SID= " + U_ID, con);
con.Open();
OleDbDataReader rd = da.SelectCommand.ExecuteReader();
if (rd.Read())
{
//txtId.Text = U_ID;
txtId.Text = rd["SID"].ToString();
}
rd.Close();
}
你可以试试这段代码
var queryString = "select * from Students where SID= " + U_ID, con;
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
txtId.Text = reader["SID"].ToString();
}
reader.Close();
}