我是 .net 的新开发者,我创建了连接 Helper 类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public static class DBConnectionHelper
{
public static SqlConnection GetConnection()
{
return new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ToString());
}
}
使用以下命令调用我的 cs 文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBConnectionHelper;
public partial class administration_login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//var DBConnectionHelper= new DBConnectionHelper();
using (var cn = DBConnectionHelper.GetConnection())
{
SqlCommand cmd = new SqlCommand("SELECT * FROM users", cn);
cn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (rdr.Read())
{
Response.Write( rdr["first_name"].ToString()+ "<br>");
// Response.Write(rdr[1].ToString()+"<br>"); //read a value
}
}
}
}
为什么我收到错误:错误 32 找不到类型或命名空间名称“ConnectionHelper”(您是否缺少 using 指令或程序集引用?)
请帮我。