App_Code 文件被忽略(Microsoft Visual Web Developer 2010 错误)
我在 Microsoft Visual Web Developer 2010 的 App_Code 文件夹中有一个“Connection.cs”文件,但它提醒我一个错误:
类型或命名空间名称 找不到“连接”(是 你缺少一个 using 指令或 装配参考?)
('Connection'是Connection.cs文件中的一个类的名称)
我对引用文件不太了解,也不明白MSDN中的错误帮助描述。我该如何修复它?
编辑:
Connection.cs 文件:
public class Connection
{
public void Insert(OleDbConnection cnctn, string tableName, string[] inputs, char[] types)
{
// new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + this.dbPath);
string sql = "INSERT INTO " + tableName + " VALUES (";
for (int i = 0; i < inputs.Length - 1; i++)
sql += "@p" + i + ",";
sql += "@p" + (inputs.Length - 1) + ")";
cnctn.Open();
OleDbCommand cmnd = new OleDbCommand(sql, cnctn);
for (int i = 0; i < inputs.Length; i++)
{
if (types[i] == 'c')
cmnd.Parameters.Add("@p" + i, OleDbType.VarChar);
else if (types[i] == 'n')
cmnd.Parameters.Add("@p" + i, OleDbType.VarNumeric);
cmnd.Parameters["@p" + i].Value = inputs[i];
}
cmnd.ExecuteNonQuery();
}
public bool DoesExists(OleDbConnection cnctn, string tableName, string condition)
{
// new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + this.dbPath);
cnctn.Open();
OleDbCommand cmnd = new OleDbCommand("SELECT * FROM " + tableName + " WHERE " + condition, cnctn);
bool temp = cmnd.ExecuteReader().Read();
cnctn.Close();
return temp;
}
public DataSet SetDataSet(OleDbConnection cnctn, string tableName, string sql)
{
cnctn.Open();
DataSet ds = new DataSet();
OleDbCommand cmnd = new OleDbCommand(sql, cnctn);
OleDbDataAdapter da = new OleDbDataAdapter(cmnd);
da.Fill(ds, tableName);
cnctn.Close();
return ds;
}
public void Execute(OleDbConnection cnctn, string sql)
{
cnctn.Open();
OleDbCommand cmnd = new OleDbCommand(sql, cnctn);
cmnd.ExecuteNonQuery();
cnctn.Close();
}
}
使用此类的文件之一:
public partial class register : System.Web.UI.Page
{
private string[] errors = new string[5];
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["submit"] != null)
{
string[] inputs = {
Request.Form["userName"],
Request.Form["names"],
Request.Form["password"],
Request.Form["email"],
Request.Form["birthDate"]
};
string[] regexString = {
@"[^&<>\n]+( [^&<>\n]+)*",
@"['\-A-z]{2,}( ['\-A-z]{2,})+",
".{5,}",
@"\w+@\w+(\.\w+)+",
@"(\d{4}-\d\d-\d\d)?"
};
char[] types = { 'u', 'i', 'i', 'i', 'd' };
bool flag = true;
OleDbConnection cnct = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Server.MapPath("App_Data/WMUdb.accdb"));
for (int i = 0; i < inputs.Length; i++)
{
if (!(new Validation(inputs[i], regexString[i], types[i], cnct, "members").isValid()))//this is another class frome the App_Code, with the same problem.
{
//error alert
flag = false;
}
}
if (flag)
{
string[] values = new string[6];
for (int i = 0; i < inputs.Length - 1; i++)
values[i] = inputs[i];
values[5] = "1";
Connection cnctn = new Connection();
cnctn.Insert(cnct, "members", values, new char[6] { 'c', 'c', 'c', 'c', 'c', 'n' });
Session["userName"] = inputs[0];
Session["adminLevel"] = 1;
Response.Redirect("homepage.aspx");
}
}
}
}
第二次编辑:
我应该提到,当我创建 App_Code 文件时,它不会自动创建项目,但手动添加 - 我使用“添加项目...”创建一个具有该名称的文件夹,向其中添加“Connection.cs”,仅此而已。
I have a 'Connection.cs' file in the App_Code folder of Microsoft Visual Web Developer 2010, but it alerts me of an error:
The type or namespace name
'Connection' could not be found (are
you missing a using directive or an
assembly reference?)
('Connection' is the name of a class in the Connection.cs file)
I don't know much about referring files, and I didn't understand the error help description in MSDN. How can I fix it?
Edit:
The Connection.cs file:
public class Connection
{
public void Insert(OleDbConnection cnctn, string tableName, string[] inputs, char[] types)
{
// new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + this.dbPath);
string sql = "INSERT INTO " + tableName + " VALUES (";
for (int i = 0; i < inputs.Length - 1; i++)
sql += "@p" + i + ",";
sql += "@p" + (inputs.Length - 1) + ")";
cnctn.Open();
OleDbCommand cmnd = new OleDbCommand(sql, cnctn);
for (int i = 0; i < inputs.Length; i++)
{
if (types[i] == 'c')
cmnd.Parameters.Add("@p" + i, OleDbType.VarChar);
else if (types[i] == 'n')
cmnd.Parameters.Add("@p" + i, OleDbType.VarNumeric);
cmnd.Parameters["@p" + i].Value = inputs[i];
}
cmnd.ExecuteNonQuery();
}
public bool DoesExists(OleDbConnection cnctn, string tableName, string condition)
{
// new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + this.dbPath);
cnctn.Open();
OleDbCommand cmnd = new OleDbCommand("SELECT * FROM " + tableName + " WHERE " + condition, cnctn);
bool temp = cmnd.ExecuteReader().Read();
cnctn.Close();
return temp;
}
public DataSet SetDataSet(OleDbConnection cnctn, string tableName, string sql)
{
cnctn.Open();
DataSet ds = new DataSet();
OleDbCommand cmnd = new OleDbCommand(sql, cnctn);
OleDbDataAdapter da = new OleDbDataAdapter(cmnd);
da.Fill(ds, tableName);
cnctn.Close();
return ds;
}
public void Execute(OleDbConnection cnctn, string sql)
{
cnctn.Open();
OleDbCommand cmnd = new OleDbCommand(sql, cnctn);
cmnd.ExecuteNonQuery();
cnctn.Close();
}
}
One of the files that uses this class:
public partial class register : System.Web.UI.Page
{
private string[] errors = new string[5];
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["submit"] != null)
{
string[] inputs = {
Request.Form["userName"],
Request.Form["names"],
Request.Form["password"],
Request.Form["email"],
Request.Form["birthDate"]
};
string[] regexString = {
@"[^&<>\n]+( [^&<>\n]+)*",
@"['\-A-z]{2,}( ['\-A-z]{2,})+",
".{5,}",
@"\w+@\w+(\.\w+)+",
@"(\d{4}-\d\d-\d\d)?"
};
char[] types = { 'u', 'i', 'i', 'i', 'd' };
bool flag = true;
OleDbConnection cnct = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Server.MapPath("App_Data/WMUdb.accdb"));
for (int i = 0; i < inputs.Length; i++)
{
if (!(new Validation(inputs[i], regexString[i], types[i], cnct, "members").isValid()))//this is another class frome the App_Code, with the same problem.
{
//error alert
flag = false;
}
}
if (flag)
{
string[] values = new string[6];
for (int i = 0; i < inputs.Length - 1; i++)
values[i] = inputs[i];
values[5] = "1";
Connection cnctn = new Connection();
cnctn.Insert(cnct, "members", values, new char[6] { 'c', 'c', 'c', 'c', 'c', 'n' });
Session["userName"] = inputs[0];
Session["adminLevel"] = 1;
Response.Redirect("homepage.aspx");
}
}
}
}
2nd Edit:
I should mention that the App_Code file wasn't created automatically when I created the project, but add manually - I used "Add Item..." to create a folder with that name, added "Connection.cs" to it and that's it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
命名空间
,卢克!(对于这两个文件来说是最好的情况)
Use
namespaces
, Luke!(for both files is the best case)