注册 登录
编程论坛 SQL Server论坛

请教:连接数据库时显示列名无效

lihui_198405 发布于 2008-08-18 15:23, 2708 次点击
编写下面的代码,运行时提示数据库表名personlike无效,应该是哪里出现问题了呢?
 protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = db.createconnection();
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from personlike",con);
            SqlDataReader sdr = cmd.ExecuteReader();            this.CheckBoxList1.DataTextField = "likeContent";
            this.CheckBoxList1.DataValueField = "id";
            this.CheckBoxList1.DataSource = sdr;
            this.CheckBoxList1.DataBind();
            sdr.Close();
            con.Close();
        }
红色行为错误提示行
2 回复
#2
bb38522008-08-19 09:21
SqlDataReader 不是这么用的
while(sdr.Read())
{
逐条记录读取
}
自己网上查查他们的用法就知道了
#3
lihui_1984052008-08-19 20:52
谢谢!
1