想把数据库中第三列的数据(男或是女读入用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; 
           }

解决方案 »

  1.   

    textBox1.Text = dr[0].ToString();
                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();
      

  2.   

    亲,我是想实现radiobutton的选择,但数据库中是“男”时,radiobutton1被选中
      

  3.   

    烽据库中字段要设为bool类型。
      

  4.   

          if (dr[3].ToString() == radioButton1.Text)
                 radioButton1.Checked=true;
               else
                 radioButton2.Checked=true; 
               }你打个断点调试下不就知道了,,看下 dr[3]的值和radiobutton1.text的值是否相等就知道了
    何必那么纠结了,,你贴上面的代码根本就不能解决,
      

  5.   

    楼上正解,自己打断点测试一下,看看dr[3]到底获取的数据是什么?然后再根据获得的数据来修改If运距的判断条件