当前位置:编程学习 > C#/ASP.NET >>

datareder problem

 string strSelect = "select * from student where student_ID ='"+tb_studentID.Text+"'";
                SqlConnection conn = new SqlConnection(strconn);
                conn.Open();
                SqlCommand cmd = new SqlCommand(strSelect, conn);
              
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
     
                while (dr.Read())
                {
                    this.tb_StuID.Text = dr["student_ID"].ToString();
                    this.tb_StuName.Text = dr["studnet_name"].ToString();
                    this.tb_classID.Text = dr["class_ID"].ToString();
                    this.combo_age.Text = dr["age"].ToString();
                    this.combo_Sex.Text = dr["易做图"].ToString();
                    this.combo_specialty.Text = dr["specialty"].ToString();
                    this.photo.Image = Image.FromFile(dr["picture"].ToString());
                    this.combo_department.Text = dr["department_name"].ToString();
                    this.combo_politic.Text = dr["politic"].ToString();
                } 
              结果:未处理 System.InvalidOperationException
  Message="在没有任何数据时进行无效的读取尝试。"
请高手指点迷津!!
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,