当前位置:编程学习 > C#/ASP.NET >>

asp.net连接mysql数据库关于ODBC的问题

我在网站目录建立了一个DB.cs的文件,在里边写了一个连接数据库的函数(如下ex1),然后在like.aspx.cs中进行调用(如下ex2),可是在调用的时候就出现了,“找不到类型或命名空间名称“DB”(是否缺少using指令或程序集引用?)”请问这该怎么解决呢?!

ex1:

using System;
using System.Data.Odbc;


namespace Test01
{
/// <summary>
/// Summary description for db.   DB得摘要说明
/// </summary>
public class db
{
public db()
{
//
// TODO: Add constructor logic here    在此处构造函数逻辑
//
}
public static OdbcConnection createodbcConnection()
{
System.Data.Odbc.OdbcConnection con=new OdbcConnection("server=.;database=login,uid=root;pwd=123456;");
return con;
}

}
}

ex2:

using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.Odbc;
namespace Test01
{
/// <summary>
/// Summary description for like.
/// </summary>
public class like : System.Web.UI.Page
{
protected System.Web.UI.WebControls.CheckBoxList CheckBoxList1;

private void Page_Load(object sender, System.EventArgs e)
{
OdbcConnection con=DB.createodbcConnection();
con.Open();
OdbcCommand cmd=new OdbcCommand("select * from personlike",con);
OdbcDataReader sdr=cmd.ExecuteReader();
this.CheckBoxList1.DataTextField="likeContent";
this.CheckBoxList1.DataValueField="id";
            this.CheckBoxList1.DataSource=sdr;
this.CheckBoxList1.DataBind();
sdr.Close();
con.Close();
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{    
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,