using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Example04.Ex04_02
{
/// <summary>
/// ex04_04 的摘要说明。
/// </summary>
public class ex04_04 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblcommstr;
protected System.Web.UI.WebControls.Button btninsert;
protected System.Web.UI.WebControls.Button btndelete;
protected System.Web.UI.WebControls.Label lblflag;
    protected SqlConnection myConn=new SqlConnection(); private void Page_Load(object sender, System.EventArgs e)

{
// 在此处放置用户代码以初始化页面
//设置myconnection 的属性
string strConn="server=Localhost;uid=sa;pwd=;database=Northwind";
myConnection.ConnectionString=strConn;
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}
编译后,出现如下的提示c:\inetpub\wwwroot\example04\Ex04_02\ex04_04.aspx.cs(33): 找不到类型或命名空间名称“myConnection”(是否缺少 using 指令或程序集引用?)

解决方案 »

  1.   

    写错了?
    myConn
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
      

  2.   

    myConnection
    是不是你缺少文件?
    myConnection是不是静态类???还是你没有定义啊???
      

  3.   

    晕,是写错了,直接MYCONN就好,谢!
      

  4.   


            protected SqlConnection myConn=new SqlConnection();   //////////这里定义的是myConn        private void Page_Load(object sender, System.EventArgs e)
                
            {
                // 在此处放置用户代码以初始化页面
                //设置myconnection 的属性
                string strConn="server=Localhost;uid=sa;pwd=;database=Northwind";
                myConnection.ConnectionString=strConn;   //这里设置连接字符串用的变量却是myConnection
            }