SqlDataReader取值问题~~
public SqlDataReader GetPersonEdu(string cPsnNum)
{
string selectStr = "select *from edu where cPsn_Num= " + cPsnNum;
this.sqlC = new SqlConnection(DBOperate.connectStr);
this.sqlCmd = new SqlCommand(selectStr,this.sqlC);
this.sqlC.Open();
this.sqlDr = this.sqlCmd.ExecuteReader();
return this.sqlDr;
}
SqlDataReader sdr1 = dbop.GetPersonEdu(dataGridView1.CurrentCell.Value.ToString());
while(sdr1.read())
{
textBox5.Text = sdr1[3].ToString();
comboBox11.Text = sdr1[4].ToString();
comboBox11.Enabled = false;
comboBox10.Text = sdr1[5].ToString();
comboBox10.Enabled = false;
}
sdr1.Close();
可是GetPersonEdu()得到的是多行记录,我要如何将其一行行记录读出来,分别赋给不同的textbox呢?
------解决方案--------------------我要如何将其一行行记录读出来,分别赋给不同的textbox呢?
========
SqlDataReader sdr1 = dbop.GetPersonEdu(dataGridView1.CurrentCell.Value.ToString());
if(sdr1.read()) {
TextBox1.Text = sdr1[0].ToString();
// ...
}
if(sdr1.read()) {
TextBox2.Text = sdr1[0].ToString();
// ...
}
if(sdr1.read()) {
TextBox3.Text = sdr1[0].ToString();
// ...
}
这种处理方式不实用,明白原理就好