string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))//automatic closing of connection- advantage
{
SqlCommand cmd = new SqlCommand("SELECT * FROM SalesLT.ImpAddress", con);
con.Open();
GridView1.DataSource(cmd.ExecuteReader().ToString());
GridView1.DataBind();
}
在DataSource上显示错误。显示的错误是:
错误1不可使用的成员'System.Web.UI.WebControls.BaseDataBoundControl.DataSource'不能像方法一样使用。
答案 0 :(得分:0)
尝试一下:
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))//automatic closing of connection- advantage
{
SqlCommand cmd = new SqlCommand("SELECT * FROM SalesLT.ImpAddress", con);
con.Open();
GridView1.DataSource=cmd.ExecuteReader();
GridView1.DataBind();
}