using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBClass;
public partial class Admin_Index : System.Web.UI.Page
{
//创建公共类CommonClass一个新实例对象
DBClass dbObj = new DBClass();
CommonClass ccObj = new CommonClass();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)//判断页面是否是第一次加载 {
this.labVali.Text = ccObj.RandomNum(4);//产生验证码
}
}
protected void btnOK_Click(object sender, EventArgs e)
{
if (this.txtVali.Text != this.labVali.Text)
{//判断验证输入错误
Response.Write(ccObj.MessageBox("验证码错误!"));
}
else
{
//判断用户输入的用户和密码是否合法
string strSql = "select * from tb_Admin where UserName='" + this.txtUid.Text + "' and PassWord='" + this.txtPwd.Text + "'";
DataTable dsTable = dbObj.GetDataSet(strSql, "tbAdmin");
if (dsTable.Rows.Count > 0)
{
Session["UserName"] = this.txtUid.Text;//保存用户名
Session["UserID"] = int.Parse(dsTable.Rows[0]["ID"].ToString());//保存用户ID代号
Session["SuperAdmin"] = dsTable.Rows[0]["SuperAdmin"].ToString();//保存管理员级别
Response.Write("<script language=javascript>window.open('AdminManage.aspx');window.close();</script>"); }
else
{//用户名和密码不合法
Response.Write(ccObj.MessageBox("用户名或密码有误!"));
return;
}
}
}
protected void btnCancle_Click(object sender, EventArgs e)
{
Response.Write("<script>window.close();location='javascript:history.go(-1)';</script>");
}
}
各位大哥大姐帮帮忙,我明明已经在App_Code文件夹下DBClass.cs的里面写了命名空间DBClass,为什么还会说Error 2 找不到类型或命名空间名称“DBClass”(是否缺少 using 指令或程序集引用?) 到底是哪错了呢?急急急
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBClass;
public partial class Admin_Index : System.Web.UI.Page
{
//创建公共类CommonClass一个新实例对象
DBClass dbObj = new DBClass();
CommonClass ccObj = new CommonClass();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)//判断页面是否是第一次加载 {
this.labVali.Text = ccObj.RandomNum(4);//产生验证码
}
}
protected void btnOK_Click(object sender, EventArgs e)
{
if (this.txtVali.Text != this.labVali.Text)
{//判断验证输入错误
Response.Write(ccObj.MessageBox("验证码错误!"));
}
else
{
//判断用户输入的用户和密码是否合法
string strSql = "select * from tb_Admin where UserName='" + this.txtUid.Text + "' and PassWord='" + this.txtPwd.Text + "'";
DataTable dsTable = dbObj.GetDataSet(strSql, "tbAdmin");
if (dsTable.Rows.Count > 0)
{
Session["UserName"] = this.txtUid.Text;//保存用户名
Session["UserID"] = int.Parse(dsTable.Rows[0]["ID"].ToString());//保存用户ID代号
Session["SuperAdmin"] = dsTable.Rows[0]["SuperAdmin"].ToString();//保存管理员级别
Response.Write("<script language=javascript>window.open('AdminManage.aspx');window.close();</script>"); }
else
{//用户名和密码不合法
Response.Write(ccObj.MessageBox("用户名或密码有误!"));
return;
}
}
}
protected void btnCancle_Click(object sender, EventArgs e)
{
Response.Write("<script>window.close();location='javascript:history.go(-1)';</script>");
}
}
各位大哥大姐帮帮忙,我明明已经在App_Code文件夹下DBClass.cs的里面写了命名空间DBClass,为什么还会说Error 2 找不到类型或命名空间名称“DBClass”(是否缺少 using 指令或程序集引用?) 到底是哪错了呢?急急急
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Blog
{
/// <summary>
/// DBClass 的摘要说明
/// </summary>
public class DBClass
{
SqlConnection myConn; //用于连接数据库
SqlCommand myCmd; //用于执行Sql语句
DataSet ds; //数据集
SqlDataAdapter adapt; //填充数据集
public DBClass()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 连接数据库
/// </summary>
/// <returns>返回SqlConnection对象</returns>
public SqlConnection GetConnection()
{
string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
myConn = new SqlConnection(myStr);
return myConn;
}
/// <summary>
/// 更新数据库
/// </summary>
/// <param name="strSql">sqlStr执行的SQL语句</param>
public void ExecNonQuery(string strSql)
{ try
{
myConn = GetConnection();//与数据库连接
myCmd = new SqlCommand();//初始化SqlCommand类对象
myCmd.Connection = myConn;
myCmd.CommandText = strSql;
if (myCmd.Connection.State != ConnectionState.Open)
{
myCmd.Connection.Open();//打开与数据库的连接
}
myCmd.ExecuteNonQuery();//执行Sql操作,并返回受影响的行数 }
catch (Exception ex)
{
throw new Exception(ex.Message, ex); }
finally
{
if (myCmd.Connection.State == ConnectionState.Open)
{//断开连接,释放资源
myCmd.Connection.Close();
myConn.Dispose();
myCmd.Dispose(); }
}
}
/// <summary>
/// 返回一个值
/// </summary>
/// <param name="strSql">sqlStr执行的SQL语句</param>
/// <returns>返回获取的值</returns>
public string ExecScalar(string strSql)
{ try
{
myConn = GetConnection();//与数据库连接
myCmd = new SqlCommand();//初始化SqlCommand类对象
myCmd.Connection = myConn;
myCmd.CommandText = strSql;
if (myCmd.Connection.State != ConnectionState.Open)
{
myCmd.Connection.Open();//打开与数据库的连接
}
//使用SqlCommand对象的ExecuteScalar方法返回第一行第一列的值
strSql = Convert.ToString(myCmd.ExecuteScalar());
return strSql; }
catch (Exception ex)
{
throw new Exception(ex.Message, ex); }
finally
{
if (myCmd.Connection.State == ConnectionState.Open)
{//断开连接,释放资源
myConn.Dispose();
myCmd.Connection.Close();
myCmd.Dispose(); }
} }
/// <summary>
/// 说 明: GetDataSet数据集,返回数据源的数据表
/// 返回值: 数据源的数据表
/// 参 数: sqlStr执行的SQL语句,TableName 数据表名称
/// </summary>
public DataTable GetDataSet(string strSql, string TableName)
{
ds = new DataSet();
try
{
myConn = GetConnection();//与数据库连接
adapt = new SqlDataAdapter(strSql, myConn); //实例化SqlDataAdapter类对象
adapt.Fill(ds, TableName);//填充数据集
return ds.Tables[TableName];//返回数据集DataSet的表的集合 }
catch (Exception ex)
{
throw new Exception(ex.Message, ex); }
finally
{//断开连接,释放资源
myConn.Close();
adapt.Dispose();
ds.Dispose();
myConn.Dispose(); } } }
}
using System.Collections.Generic;
using System.Linq;
using System.Web;namespace Blog
{ /// <summary>
/// Summary description for DBClass
/// </summary>
public class DBClass
{ //
// TODO: Add constructor logic here
//
public DBClass()
{
} public void OutputDummy(string input)
{
Console.WriteLine(input);
} }}
Page behind class:using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Blog;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DBClass myclass = new DBClass();
myclass.OutputDummy("aaa");
}
}
Vs2008,工程类型是web site.
好像App_Code在Web application类型的工程中不起作用。
就没有问题了。
而不是using dbclass;
2.把dbclass单独放到一个新的类库项目中去,再引用该dll目前你是什么状态,dbclass在哪儿?有无namespace?
这个是什么意思呢?看不明白。现在还是和之前一样,没进展。类dbclass放在app_code文件夹下,有namespace,名为Blog