本文介绍了找不到类型或命名空间名称'connection'(您是否缺少using指令或程序集引用?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在app-code文件夹中有一个名为connection的连接类,我在aspx.cs文件中调用它,例如 connection c = new connection(); 它在本地主机上工作正常,但是当我上传所有文件时,它会抛出错误找不到命名空间名称'connection'(你是否缺少using指令或程序集引用?) 如何解决这个问题? 我的连接文件代码: 使用系统; 使用 System.Collections.Generic; 使用 System.Linq; 使用 System.Web; 使用 System.Data.SqlClient; 使用 System.Data; 使用 System.Web.UI.WebControls; 使用 System.Configuration; /// < ; 摘要 > /// 连接的摘要说明 /// < / summary > public class connection { public SqlConnection con = new SqlConnection(); public SqlCommand cmd = new SqlCommand(); public SqlDataAdapter adp = new SqlDataAdapter(); public DataSet ds = new DataSet(); public DataRow dr; public SqlCommandBuilder scb; public connection() { con.ConnectionString = ConfigurationManager.ConnectionStrings [ email]。ConnectionString; adp.SelectCommand = cmd; cmd.Connection = con; // // TODO:在此处添加构造函数逻辑 // } public void ddlbind( string query, string text, string value ,DropDownList id) { ds.Clear(); cmd.CommandText = query; adp.Fill(ds, vt); id.DataSource = ds.Tables [ vt]; id.DataTextField = text; id.DataValueField = value ; id.DataBind(); id.Items.Insert( 0 , - 选择 - ); } public void gridbind(GridView id, string query) { ds.Clear(); cmd.CommandText = query; adp.Fill(ds, vt); id.DataSource = ds.Tables [ vt]; id.DataBind(); } public void databind(DataList id, string query) { ds.Clear(); cmd.CommandText = query; adp.Fill(ds, vt); id.DataSource = ds.Tables [ vt]; id.DataBind(); } public void detailsbind(DetailsView id, string query) { ds.Clear(); cmd.CommandText = query; adp.Fill(ds, vt); id.DataSource = ds.Tables [ vt]; id.DataBind(); } public void listbind(ListView id, string query) { ds.Clear(); cmd.CommandText = query; adp.Fill(ds, vt); id.DataSource = ds.Tables [ vt]; id.DataBind(); } } 和.aspx页码是 - 使用系统; 使用 System.Collections; 使用 System.Configuration; 使用 System.Data; 使用 System.Linq; 使用 System.Web; 使用 System.Web.Security; 使用 System.Web.UI; 使用 System.Web.UI.HtmlControls; 使用 System.Web.UI.WebControls; 使用 System.Web.UI.WebControls.WebParts; 使用 System.Xml.Linq; 使用 System.Text; 使用 System.Data.SqlClient; 使用 System.Net.Mail; public partial class bulkemail:System.Web.UI.Page { connection c = new connection(); public string server1 = gmail.com,user_id = avatys99 @ gmail .com,pass = 9198430645; 受保护 void Page_Load( object sender,EventArgs e) { if (!IsPostBack) { 尝试 { c.cmd.CommandText = SELECT *来自SYS.TABLES; c.adp.Fill(c.ds, dk); DropDownList1.DataSource = c.ds.Tables [ dk]; DropDownList1.DataTextField = c.ds.Tables [ dk]。列[ name]。ToString(); DropDownList1.DataValueField = c.ds.Tables [ dk]。列[ name]。ToString(); DropDownList1.DataBind(); DropDownList1.Items.Insert( 0 , - 选择 - ); c.cmd.CommandText = 从excel选择计数(*)为dd; c.adp.Fill(c.ds, vt); } catch (例外情况) { Console.WriteLine( {0}异常被捕获。,ex); } } } 受保护 void ImageButton1_Click( object sender,ImageClickEventArgs e) { string body = 名称: + txtsubject.Text + < br /> 消息: + txtmsg.Text; 尝试 {标签lblname = 新标签(); lblname.Text = DropDownList1.SelectedItem.Text; MailMessage Msg = new MailMessage(); // 发件人电子邮件地址。 Msg.From = new MailAddress( [email protected] ); // 收件人电子邮件地址。 c.cmd.CommandText = select * from + [ + DropDownList1.SelectedItem.Value + ] + ; c.adp.Fill(c.ds, vt1); // string s = c.ds.Tables [vt1]。行[i] [ elist]。ToString(); int i = 0 ; int eid = Convert.ToInt32(c.ds.Tables [ vt]。行[ 0 ] [ dd]。ToString()); for (i = 0 ; i < ; eid; i ++) { string s = c.ds.Tables [ vt1]。行[i] [ 电子邮件]的ToString(); Msg.To.Add(s); } Msg.To.Add( [email protected] ); Msg.Subject = txtsubject.Text; Msg.IsBodyHtml = true ; Msg.Body = body; // 您的远程SMTP服务器IP。 SmtpClient smtp = new SmtpClient(); smtp.Host = smtp.gmail.com; smtp.Port = 587 ; smtp.Credentials = new System.Net.NetworkCredential( [email protected], 9198430645); smtp.EnableSsl = true ; smtp.Send(Msg); Msg = null ; txtsubject.Text = ; txtmsg.Text = ; lblmsg.Text = 邮件发送成功; Page.ClientScript.RegisterStartupScript( this .GetType(), msg, < script> alert('Mail send Successfully')< ; /脚本>)); } catch (例外情况) { Console.WriteLine( {0}异常被捕获。,ex); lblmsg.Text = Mail not Send; Page.ClientScript.RegisterStartupScript( this .GetType(), msg, < script> alert('Mail not Send')< ; /脚本>)); } } } 解决方案 如果您的项目 是一个Web应用程序项目,请不要 check 如果 类的构建操作属性(选择类和点击F4) set as ' 仅编译' 。它应 set as ' Content'。 当将部署到 Web服务器时,Web应用程序项目会包装其app_code 中的类文件和将 bin文件夹。确保已将bin文件夹部署到 Web服务器。 如果您的项目 一个网站类型,然后在根目录上部署app_code文件夹应该使网站正常工作。 如果 ,请告诉我们 I have a connection class named "connection" in app-code folder and I called it in aspx.cs file likeconnection c=new connection();It works fine on local host but when I upload all files then it throw error "The type or namespace name 'connection' could not be found (are you missing a using directive or an assembly reference?)"How can i fix this?my connection file code:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data.SqlClient;using System.Data;using System.Web.UI.WebControls;using System.Configuration;/// <summary>/// Summary description for connection/// </summary>public class connection{ public SqlConnection con = new SqlConnection(); public SqlCommand cmd = new SqlCommand(); public SqlDataAdapter adp = new SqlDataAdapter(); public DataSet ds = new DataSet(); public DataRow dr; public SqlCommandBuilder scb;public connection(){ con.ConnectionString = ConfigurationManager.ConnectionStrings["email"].ConnectionString; adp.SelectCommand = cmd; cmd.Connection = con;//// TODO: Add constructor logic here//} public void ddlbind(string query, string text, string value, DropDownList id) { ds.Clear(); cmd.CommandText = query; adp.Fill(ds, "vt"); id.DataSource = ds.Tables["vt"]; id.DataTextField = text; id.DataValueField = value; id.DataBind(); id.Items.Insert(0, "--Select--"); } public void gridbind(GridView id, string query) { ds.Clear(); cmd.CommandText = query; adp.Fill(ds, "vt"); id.DataSource = ds.Tables["vt"]; id.DataBind(); } public void databind(DataList id, string query) { ds.Clear(); cmd.CommandText = query; adp.Fill(ds, "vt"); id.DataSource = ds.Tables["vt"]; id.DataBind(); } public void detailsbind(DetailsView id, string query) { ds.Clear(); cmd.CommandText = query; adp.Fill(ds, "vt"); id.DataSource = ds.Tables["vt"]; id.DataBind(); } public void listbind(ListView id, string query) { ds.Clear(); cmd.CommandText = query; adp.Fill(ds, "vt"); id.DataSource = ds.Tables["vt"]; id.DataBind(); }}and .aspx page code is-using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Text;using System.Data.SqlClient;using System.Net.Mail;public partial class bulkemail : System.Web.UI.Page{ connection c = new connection(); public string server1 = "gmail.com", user_id = "[email protected]", pass = "9198430645"; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { c.cmd.CommandText = "SELECT * FROM SYS.TABLES"; c.adp.Fill(c.ds, "dk"); DropDownList1.DataSource = c.ds.Tables["dk"]; DropDownList1.DataTextField = c.ds.Tables["dk"].Columns["name"].ToString(); DropDownList1.DataValueField = c.ds.Tables["dk"].Columns["name"].ToString(); DropDownList1.DataBind(); DropDownList1.Items.Insert(0, "--Select--"); c.cmd.CommandText = "select count(*) as dd from excel"; c.adp.Fill(c.ds, "vt"); } catch (Exception ex) { Console.WriteLine("{0} Exception caught.", ex); } } } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { string body = "Name : " + txtsubject.Text + "<br />message : " + txtmsg.Text; try { Label lblname = new Label(); lblname.Text = DropDownList1.SelectedItem.Text; MailMessage Msg = new MailMessage(); // Sender e-mail address. Msg.From = new MailAddress("[email protected]"); // Recipient e-mail address. c.cmd.CommandText = "select * from" + " [" + DropDownList1.SelectedItem.Value + "]" + ""; c.adp.Fill(c.ds, "vt1"); //string s = c.ds.Tables["vt1"].Rows[i]["elist"].ToString(); int i = 0; int eid = Convert.ToInt32(c.ds.Tables["vt"].Rows[0]["dd"].ToString()); for (i = 0; i < eid; i++) { string s = c.ds.Tables["vt1"].Rows[i]["email"].ToString(); Msg.To.Add(s); } Msg.To.Add("[email protected]"); Msg.Subject = txtsubject.Text; Msg.IsBodyHtml = true; Msg.Body = body; // your remote SMTP server IP. SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "9198430645"); smtp.EnableSsl = true; smtp.Send(Msg); Msg = null; txtsubject.Text = ""; txtmsg.Text = ""; lblmsg.Text = "Mail send Successfully"; Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('Mail send Successfully' )</script>)"); } catch (Exception ex) { Console.WriteLine("{0} Exception caught.", ex); lblmsg.Text = "Mail not Send"; Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('Mail not Send' )</script>)"); } }} 解决方案 If your project is a web application project, can you please check if the Build Action property of the class (Select class and hit F4) is set as 'Compile Only'. It should not be set as 'Content'.When you deploy to web server, a web application project wraps its app_code class files in a dll and would be available in the bin folder. Make sure that you have deployed your bin folder to the web server.If your project is a website type, then deploying the app_code folder on the root should make the site work.Let us know if this works for you. 这篇关于找不到类型或命名空间名称'connection'(您是否缺少using指令或程序集引用?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-28 02:44