分享

SqlDataReader对象可以绑定到数据集(如GridView)

 寒木萧条 2010-10-21
 
           SqlDataReader对象可以绑定到数据集(如GridView),
           代码如下:
 
           SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["teachConn"].ConnectionString;
            string strSql;
            strSql = "select s_no as 学号,s_name as 姓名,s_sex as 性别,s_birthday as 生日,s_department as 专业 from student where s_no=" +Int64.Parse(txtCheckCondition.Text.Trim().ToString());
            conn.Open();
            SqlDataReader dtReader = comm.ExecuteReader();
            //用SqlDataReader进行数据绑定,不能调用SqlDataReader的Read()方法(即dtReader.Read()),否则会错误的
            gvCheckCondition.DataSource = dtReader;
            gvCheckCondition.DataBind();
            dtReader.Close();
            dtReader.Dispose();           
            conn.Close();
            conn.Dispose();

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多