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

CS0246: 找不到类型或命名空间名称“SiteDb”(是否缺少 using 指令或程序集引用?)

文件index_.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
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.Web.Security;

namespace WebSite3
{
    public partial class user_loginx : System.Web.UI.Page
    {
        public int ii;
        
        private void Page_Load(object sender, System.EventArgs e)
        {
            
            if (Session["UserName"] == null)
            {
                Response.Redirect("index_.aspx");
            }
            else
            {
                Response.Redirect("index.aspx");
            }

        }

        public void SubMit_Click(object sender, EventArgs e)
        {
            SiteDb sitedb = new SiteDb();
            string SqlSelect = "select * from USER where user_name='" + username.Text + "' and password='" + user_password + "'";
            if (sitedb.UserName_Select(SqlSelect) > 0)
            {
                Session["UserName"] = username.Text;

            }
            else
            {
                Response.Write("<script>alert('用户名或密码错误');</script>");
                Response.Write("<script>history.go(-1);</script>");
            }

        }



    }

}




文件SiteDb.cs
using System;
using System.Web;
using System.Data;
using System.Data.OleDb;

namespace WebSite3
{

    public class SiteDb
    {
        public int v3, ii, i;
        public int StartIndex = 0;

        public int UserName_Select(string SqlSelect)
        {
            string dbPath = System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
            string ACconnStr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + HttpContext.Current.Server.MapPath(dbPath);
            OleDbConnection ACconn = new OleDbConnection(ACconnStr);
            ACconn.Open();
            OleDbCommand ACcomm = new OleDbCommand(SqlSelect, ACconn);
            OleDbDataReader ACdr = ACcomm.ExecuteReader();
            if (ACdr.Read())
            {
                v3 = Convert.ToInt32(ACdr[3].ToString());
            }

            ACdr.Close();
            ACconn.Close();
            return v3;
        }



        public int IBM_SQL(string SqlSelect)
        {
            string dbPath = System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
            string ACconnStr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + HttpContext.Current.Server.MapPath(dbPath);
            OleDbConnection ACconn = new OleDbConnection(ACconnStr);
            ACconn.Open();
            OleDbCommand ACcomm = new OleDbCommand(SqlSelect, ACconn);
            ii = ACcomm.ExecuteNonQuery();
            ACconn.Close();
            return ii;

        }


        public DataTable IBM_SqlDataAdapter(string SqlSelect)
        {

            //取得web.config中定义的数据库连接字符串
            string dbPath = System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
            //定义数据库连接字符串
            string ACconnStr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + HttpContext.Current.Server.MapPath(dbPath);
            //创建数据库连接对象
            OleDbConnection ACconn = new OleDbConnection(ACconnStr);
            //创建DataAdapter对像
            OleDbDataAdapter ACda = new OleDbDataAdapter(SqlSelect, ACconn);
            //创建数据集
            DataSet ds = new DataSet();
            //填充数据集
            ACda.Fill(ds, "defaulttable");
            return ds.Tables["defaulttable"];

        }

        public DataSet IBM_DataSet(string SqlSelect)
        {

            //取得web.config中定义的数据库连接字符串
            string dbPath = System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
            //定义数据库连接字符串
            string ACconnStr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + HttpContext.Current.Server.MapPath(dbPath);
            //创建数据库连接对象
            OleDbConnection ACconn = new OleDbConnection(ACconnStr);
            //创建DataAdapter对像
            OleDbDataAdapter ACda = new OleDbDataAdapter(SqlSelect, ACconn);
            //创建数据集
            DataSet ACds = new DataSet();
            //填充数据集
            return ACds;

        }

        public int AExecuteReader(string SqlSelect)
        {


            //取得web.config中定义的数据库连接字符串
            string dbPath = System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
            //定义数据库连接字符串
            string ACconnStr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + HttpContext.Current.Server.MapPath(dbPath);
            //创建数据库连接对象
            OleDbConnection ACconn = new OleDbConnection(ACconnStr);
            //打开数据库
            ACconn.Open();
            //创建Command对象
            OleDbCommand ACcomm = new OleDbCommand(SqlSelect, ACconn);

            //实例化DataReader对象
            OleDbDataReader ACdr = ACcomm.ExecuteReader();
            if (ACdr.Read())
            {
                i = Convert.ToInt32(ACdr[0].ToString());
            }

            ACdr.Close();
            //关闭数据库
            ACconn.Close();
            return i;
        }




    }

}


谢谢各位了
--------------------编程问答-------------------- 够明显了,   SiteDb 这个东西引用不正确,有没包含在项目中,引用出问题了 --------------------编程问答-------------------- 看一下引用 --------------------编程问答-------------------- SiteDb sitedb = new SiteDb();这句吗? --------------------编程问答-------------------- 确保SiteDb被添加到了你的引用里面

确保Using中有SiteDb --------------------编程问答-------------------- 没引用呗 --------------------编程问答-------------------- using WebSite3.SiteDb;
引用后报错:CS0234: 命名空间“WebSite3”中不存在类型或命名空间名称“SiteDb”(是缺少程序集引用吗?)
--------------------编程问答-------------------- 我也遇到了这个问题,是怎么回事啊,求正解
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,