想把数据库中第三列的数据(男或是女读入用radiobutton1或是radiobutton2显示)可是这个程序运行出的结果,显示出来有误,都是radiobutt2
private void button7_Click(object sender, EventArgs e)
{
SqlConnection conn;
string str = "server=.;database=zy;Integrated Security=true";
conn = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("select * from student", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable Sno = ds.Tables[0];
DataRow dr = Sno.Rows[0]; textBox1.Text = dr[0].ToString();
textBox2.Text = dr[1].ToString();
textBox3.Text = dr[2].ToString();
textBox4.Text = dr[4].ToString();
label9.Text = 1.ToString();
if (dr[3].ToString() == radioButton1.Text)
radioButton1.Checked=true;
else
radioButton2.Checked=true;
}
textBox2.Text = dr[1].ToString();
textBox3.Text = dr[2].ToString();
textBox4.Text = dr[4].ToString();
=〉
textBox1.Text = Sno.Rows[0][3].ToString();
textBox2.Text = Sno.Rows[1][3].ToString();
textBox3.Text = Sno.Rows[2][3].ToString();
textBox4.Text = Sno.Rows[3][3].ToString();
radioButton1.Checked=true;
else
radioButton2.Checked=true;
}你打个断点调试下不就知道了,,看下 dr[3]的值和radiobutton1.text的值是否相等就知道了
何必那么纠结了,,你贴上面的代码根本就不能解决,