asp.net调用类的问题!~

来源:百度知道 编辑:UC知道 时间:2024/06/06 04:24:03
……
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace us1
{

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
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();
}
}
db.cs 的类文件代码如下:
……
using System.Web.UI.HtmlC

你在调用类的时候没有对类进行实例化,建立数据库连接的代码改成如下试试。
DB db=new DB();
SqlConnection con = db.createConnection();
con.Open();

命名控件没有引用对吧....