我的问题是我在控制台上不断收到错误消息
无效的对象名称“dbo.Products”
我正在使用 Visual C# 2008 Express Edition 和 SQL Server 2008 Express。
我在准备/安装Northwind
示例数据库时遇到了一些问题,所以我不确定这是否对这个问题有任何影响。我们的老师给出了一个测试程序,这是我收到此错误的程序。
static void Main()
{
string connectionString =
"Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Andrew\\Desktop\\SQL Server 2000 Sample Databases\\PUBS.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True";
string queryString =
"SELECT ProductID, UnitPrice, ProductName FROM dbo.Products "
+ "WHERE UnitPrice > @pricePoint "
+ "ORDER BY UnitPrice DESC;";
int paramValue = 5;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
command.Parameters.AddWithValue("@pricePoint", paramValue);
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("\t{0}\t{1}\t{2}",
reader[0], reader[1], reader[2]);
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}