b/s结构的  asp.net(c#)程序开头有using System.Data;但是为什么必须要这样写
System.Data.SqlClient.SqlConnection cn=new System.Data.SqlClient.SqlConnection();  
不能写成 SqlClient.SqlConnection cn=new SqlClient.SqlConnection();  会报错。难道我的.net系统的设置有问题?
在vb.net 里的模块 好像在c#里没有了。那我怎么声明一个全局变量啊?

解决方案 »

  1.   

    1.应该再加一个引用using System.Data.SqlClient;然后直接写成SqlConnection cn = new SqlClient.SqlConnection(); 不然就要写全名称空间,因为using System.Data;与using System.Data.SqlClient;这两个不是在一个名称空间中
    2.C#中没有全局变量。因为C#中全部都是类
      

  2.   

    在C#中所有的类必须写进命名空间中,而你在引用时必须指出类所在的命名空间中,System.Data.SqlClient.SqlConnection cn=new System.Data.SqlClient.SqlConnection这样子写的话当然是很费时的,所以在C#中一开始就得引用命名空间你直接就像在C中打开头文件的那个样子加上对命名空间的引用就OK了
      如下:
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.SqlClient;
    这样子后就可以对System.Data.SqlClient所有类进行实例,引用,所以上边一句代码就可以简化成这样了:
      SqlConnection cn=new SqlConnection(String Conname)//在实例时首先指出所属类,并调用类的构造函数!
      

  3.   

    In the Framework help doc, we can find the following statement:Using the System.Data.SqlClient namespace (the .NET Framework Data Provider for SQL Server), the System.Data.Odbc namespace (the .NET Framework Data Provider for ODBC), or the System.Data.OleDb namespace (the .NET Framework Data Provider for OLE DB), you can access a data source to use in conjunction with a DataSet. Each .NET data provider has a corresponding DataAdapter that you use as a bridge between a data source and a DataSet.so when we use the "new", we have to use the System.Data.SqlClient namespace, or we must use the code:System.Data.SqlClient.SqlConnection cn=new ystem.Data.SqlClient.SqlConnection();