【发布时间】:2015-11-10 08:52:06
【问题描述】:
我写了这段代码,但它不起作用。给出无效的对象名称“库存”。有什么建议吗?
using (SqlConnection cn = new SqlConnection())
{
cn.ConnectionString =
@"Data Source=(local);Integrated Security=SSPI;" +
"Initial Catalog=AutoLot";
cn.Open();
string strSQL = "Select * From Inventory";
SqlCommand myCommand = new SqlCommand(strSQL, cn);
// Obtain a data reader a la ExecuteReader().
using (SqlDataReader mydatareader = mycommand.ExecuteReader())
{}
【问题讨论】:
-
错误很明显 - 您的数据库不包含表
Inventory。 是否AutoLot数据库包含一个名为Inventory的表? 您是否有权阅读它? -
你也确定这个
Inventory表在默认模式中吗? -
Inventory表在什么模式中?是dbo.Inventory吗?还是...? -
怀疑错误消息的表名前有等号 (
=Inventory) - 您真的复制并粘贴了您的代码吗?或者您是否尝试重现您认为您的代码所说的内容? -
另外:它是 相同的大小写 吗? SQL Server 是否区分大小写是一个配置设置;最好的做法是始终把它做好,即使它会变得不敏感