请大家帮忙看看下边这段代码,为什么selectDoctorDr.Read()读不出值呢?
我用这里的select语句在查询分析器里读也好使,怎么回事?
谢谢了先int selectDep = regtype.SelectedIndex +1; //regtype:listbox控件
int selectDocType = departement.SelectedIndex +4;//department:listbox控件
string strProvider = "server=localhost;uid=sa;pwd=123456;database=HIS";
string strSelectDoctor = "select * from His_User where departement_id = '"+selectDep+"' and doctor_typeid = '"+selectDocType.ToString()+"'";
SqlConnection myConn = new SqlConnection(strProvider);
myConn.Open();
SqlCommand selectDoctorComm = new SqlCommand(strSelectDoctor,myConn);
SqlDataReader selectDoctorDr = selectDoctorComm.ExecuteReader();
doctor.Items.Add(selectDoctorDr.Read().ToString());selectDoctorDr.Close();
myConn.Close();
我用这里的select语句在查询分析器里读也好使,怎么回事?
谢谢了先int selectDep = regtype.SelectedIndex +1; //regtype:listbox控件
int selectDocType = departement.SelectedIndex +4;//department:listbox控件
string strProvider = "server=localhost;uid=sa;pwd=123456;database=HIS";
string strSelectDoctor = "select * from His_User where departement_id = '"+selectDep+"' and doctor_typeid = '"+selectDocType.ToString()+"'";
SqlConnection myConn = new SqlConnection(strProvider);
myConn.Open();
SqlCommand selectDoctorComm = new SqlCommand(strSelectDoctor,myConn);
SqlDataReader selectDoctorDr = selectDoctorComm.ExecuteReader();
doctor.Items.Add(selectDoctorDr.Read().ToString());selectDoctorDr.Close();
myConn.Close();
if( selectDoctorDr.Read())//加一句,因为,reader 一开始是在数据头前面{
doctor.Items.Add(selectDoctorDr.Read().ToString());
}
selectDoctorDr.Close();
myConn.Close();