怎么调用类文件
我在我的站点中定义了一个db.cs类文件怎么在页面中调用呢?例如:
public class DB:System.Web.UI.Page
{
public DB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static OleDbConnection DBconntion()
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+HttpContext.Current.Server.MapPath("app_data/it.mdb");
return conn;
}
public static DataTable DBtable(string sql)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("app_data/it.mdb");
conn.Open();
OleDbCommand comm = new OleDbCommand(sql,conn);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = comm;
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
return ds.Tables[0] ;
}}
怎么在后边调用它呢?
OleDbConnection conn;
OleDbCommand DBtable;
protected void Page_Load(object sender, EventArgs e)
{
conn = DB.DBconntion();
conn.Open();
//OleDbConnection conn = new OleDbConnection();
//conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("app_data/it.mdb");
//conn.Open();
string sql = "select * from zx";
DB dt = new DB();
DataTable dts = DB.DBtable();
//OleDbCommand comm = new OleDbCommand(sql, conn);
//OleDbDataAdapter da = new OleDbDataAdapter();
//da.SelectCommand = comm;
//DataSet ds = new DataSet();
//da.Fill(ds);
//conn.Close();
DataList1.DataSource =dts;
DataList1.DataBind();
}
这样写的话红色的部分报错!!
要怎么写呢?