c# datagrid的绑定

还是直接上代码吧,直观。

 using (SqlDataReader recu = company.Proc_SearchCompany(Companyname,Companycode,Companyperson,Tel,Mail, sqlHelper))  //这是存储过程哟
        {
            if (recu.HasRows)
            {
                ///创建DataSet数据源
                DataTable dataTable = new DataTable();

                dataTable.Load(recu);

                DataSet dataSet = new DataSet("Company");
                dataSet.Tables.Add(dataTable);

                ///设定控件的数据源
                CompanyList.DataSource = dataSet;
                ///绑定控件的数据
                CompanyList.DataBind();
            }
            else
            {
                ///设定控件的数据源
                CompanyList.DataSource = null;
                ///绑定控件的数据
                CompanyList.DataBind();
            }
            recu.Close();
            sqlHelper.Close();
            recu.Dispose();
            sqlHelper.Dispose();

 

你可能感兴趣的:(技术文章)