SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=sa;database=your databease");
con.open();
string Provincesql = "SELECT * FROM table1";
SqlCommand comm = new SqlCommand(Provincesql, conn);
SqlDataReader dr = comm.ExecuteReader();
datagrid1.DataSource = dr;
datagrid1.DataBind();
datalist如下:
SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=sa;database=your databease");
con.open();
string Provincesql = "SELECT * FROM table1";
SqlDataAdapter adapter = new SqlDataAdapter(Provincesql, conn);
DataSet ds = new DataSet();
adapter.Fill(ds, "company");
DataList1.DataSource=ds;
DataList1.DataBind();
页面部分的操作如下:
<%#DataBinder.Eval(Container.DataItem,"field(在table1中的任意字段)") %>
代码已运行通过,楼主试下。