SqlConnection connection = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Integrated Security=True;" +“Initial Catalog = Northwind");
            connection.Open();
            string strSQL = "SELECT CustomerID from Customers";
            SqlCommand cmd = new SqlCommand(strSQL, connection);
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
               Console.WriteLine("\t{0}",reader["CustomerID"]);
            }
            reader.Close();
            connection.Close();部分程序如上,运行错误提示:对象名'Customers'无效
Customers明明存在的为什么会出现这样的问题呐?请教下各位高手应该如何解决?

解决方案 »

  1.   

    Customers这个表在数据库Northwind中吗?楼主仔细看下有没有吧!
      

  2.   

    string connstring="User ID=sa;PWD=;Data Source=.;Initial Catalog= Northwind";  
    或者 sql = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog= Northwind;Integrated Security=True");
      

  3.   

    连接字符串应该没有问题啊 数据库里面的确存在Customers
    郁闷随便请问下:Northwind的文件位置在哪里,一般可以找到
      

  4.   


    还有这种事?
    不应该啊。
    Northwind的文件就在你安装数据库数据文件所指定路径的位置。
      

  5.   

    在MSSQL\Data文件夹下啊!这要看你装数据库的时候你数据文件的安装目录了!
    是不是访问权限问题呢?
      

  6.   

    SqlConnection connection = new SqlConnection(@"Data Source=.;Initial Catalog= Northwind;Integrated Security=True");
                connection.Open();
                string strSQL = "SELECT CustomerID from Customers";
                SqlCommand cmd = new SqlCommand(strSQL, connection);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    MessageBox.Show( reader["CustomerID"].ToString());
                }
    这样做没错!
      

  7.   

    我是用SQL2000的!不过没都用你的,稍微改了下连接字符串!
      

  8.   

    要是你单独有SQL SERVER的,那你直接连接就可以了啊!我没用过你这方式!呵呵