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明明存在的为什么会出现这样的问题呐?请教下各位高手应该如何解决?
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明明存在的为什么会出现这样的问题呐?请教下各位高手应该如何解决?
或者 sql = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog= Northwind;Integrated Security=True");
郁闷随便请问下:Northwind的文件位置在哪里,一般可以找到
还有这种事?
不应该啊。
Northwind的文件就在你安装数据库数据文件所指定路径的位置。
是不是访问权限问题呢?
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());
}
这样做没错!