public partial class ADOTEST : System.Web.UI.Page {
SqlDataAdapter da = null;
SqlConnection cn = null;
DataSet ds = null;
protected void Page_Load(object sender, EventArgs e)
{
cn = new SqlConnection("Data Source=(local); Database=TestDb ; Uid=sa ; password=123 ");
if (!Page.IsPostBack)
{
BindEmpData();
}
}
void BindEmpData()
{
da = new SqlDataAdapter("Select *From EMPLOYEE", cn);
ds = new DataSet();
da.Fill(ds, "EMPLOYEE");
Repeater1.DataSource = ds.Tables["EMPLOYEE"];
// Repeater1.DataSource = ds;
// Repeater1.DataMember = "EMPLOYEE";
Repeater1.DataBind();
}
答案 0 :(得分:1)
我认为连接字符串是错误的,而“选择”也是错误的
"*From"
"* From"
答案 1 :(得分:0)
为了您将来的参考,以下可能是一个更好的主意:
public partial class ADOTEST : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindEmpData();
}
}
void BindEmpData()
{
using (SqlConnection cn = new SqlConnection("Data Source=(local); Database=TestDb ; Uid=sa ; password=123 "))
{
using (SqlDataAdapter da = new SqlDataAdapter("Select *From EMPLOYEE", cn))
{
DataSet ds = new DataSet();
da.Fill(ds, "EMPLOYEE");
}
}
Repeater1.DataSource = ds.Tables["EMPLOYEE"];
Repeater1.DataBind();
}
}
using
块将确保清除资源,即使发生异常也是如此。