DataSet myDataSet = new DataSet();
string sConnect;
            sConnect = "initial catalog=Student Information; Server = CUTEMITE";
            SqlConnection dbConn = new SqlConnection(sConnect);
try
{
SQL.SqlCommand dbCmd;
                dbCmd = new SQL.SqlCommand(qurey,dbConn);                SQL.SqlDataAdapter dbAdapter;
                dbAdapter = new SQL.SqlDataAdapter(dbCmd);
  
dbConn.Open();
                 dbAdapter.Fill(myDataSet);
                dbConn.Close();
}
catch (Exception ex)
{
throw ex;

}
finally
{
dbConn.Close();
} return myDataSet;
为什么一直有错啊?Error 2 The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?) E:\520\c\SIS\SIS\DB.cs 91 13 SISError 4 The best overloaded method match 
for 'System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)' has some invalid arguments E:\520\c\SIS\SIS\DB.cs 97 25 SIS请教高手~~

解决方案 »

  1.   

    using System.Data;
    using System.Data.SqlClient;
      

  2.   

    using System.Data;
    using System.Data.SqlClient;
    写了的
      

  3.   

    先在页首引用
    using System.Data;
    using System.Data.SqlClient;
      

  4.   

    SQLConnection MyConnection; 
    SQLDataAdapter MyCommand; void Page_Load(object sender, EventArgs e) 

     MyConnection = new SqlConnection("server=localhost;Initial Catalog=pubs;uid=sa;pwd="); 
     if (!(IsPostBack)) { 
       BindGrid(); 
     } 
    } void BindGrid() 

     SQLDataAdapter MyCommand = new SQLDataAdapter("SELECT * FROM authors", MyConnection); 
     DataSet DS = new DataSet(); 
     MyCommand.Fill(DS, "min"); 
     MyDataGrid.DataSource = DS.Tables("min").DefaultView; 
     MyDataGrid.DataBind(); 
    }
      

  5.   

    你用的是windows登陆方式吗,如果是的话,字符串好像有问题,具体怎么写,你查查吧
      

  6.   

    1.引用SqlClint?
    2.连接字符串没有写正确
      

  7.   

    两种访问模式
    1.WINDOWS 不用写用户名与密码,但要加一句  integrated security=SSPI
    2.SQL 要求输入用户名与密码
      

  8.   

    WINDOWS 不用写用户名与密码,但要加一句  integrated security=SSPI
      

  9.   

    1. system.data引用可能被删除,检查 解决方案管理器->你的项目->引用->查看是否有system.data
    2.加入
    using system.data;
    using system.data.sqlclient;
    3.连接字串写得有问题,未指明连接方式。