private void search_Click(object sender, EventArgs e)
{
string Cstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=teach_online.MDB";
// string sqlstr = "create table student (Sno char(8) not null primary key,Sname char(20))";
string sqlstr = "select 教师名字,性别 from teacher;";// where 教师号='" + textBox1.Text.ToString()+"';";
OleDbConnection mydbconn = new OleDbConnection(Cstring);
OleDbCommand mycommand = new OleDbCommand(sqlstr, mydbconn);
mydbconn.Open();
OleDbDataReader dr = mycommand.ExecuteReader();
MessageBox.Show(dr[1].ToString()); mydbconn.Close();
}
为什么总是出错提示,不存在指定的行或列数据,我数据库中明明有teacher表啊 并且里面还有两行数据,谁帮帮我啊
{
string Cstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=teach_online.MDB";
// string sqlstr = "create table student (Sno char(8) not null primary key,Sname char(20))";
string sqlstr = "select 教师名字,性别 from teacher;";// where 教师号='" + textBox1.Text.ToString()+"';";
OleDbConnection mydbconn = new OleDbConnection(Cstring);
OleDbCommand mycommand = new OleDbCommand(sqlstr, mydbconn);
mydbconn.Open();
OleDbDataReader dr = mycommand.ExecuteReader();
MessageBox.Show(dr[1].ToString()); mydbconn.Close();
}
为什么总是出错提示,不存在指定的行或列数据,我数据库中明明有teacher表啊 并且里面还有两行数据,谁帮帮我啊
MessageBox.Show(dr[1].ToString());
}
而且读取后就不能在返回读取了
dr.Read();//加上这句
MessageBox.Show(dr[1].ToString());
MessageBox.Show(dr[1].ToString());
前面
加上个
dr.read()