无效的对象名称“dbo.Item” [英] Invalid object name 'dbo.Item'

查看:217
本文介绍了无效的对象名称“dbo.Item”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很喜欢C#,并尝试使用本地数据库查找方便的adaper-dataset组合。虽然我很惊讶,这是多么容易和有用的我偶然发现一个问题:



每当我尝试用适配器填充Item表时,我得到无效的对象名称SQLexception,
我对我所有的表dsOns.Users / dsOns.Items使用相同的数据集。
问题是,用户适配器确实识别并成功使用用户数据库(dbo.Users),而项目适配器找不到表(dbo.Item)。



Heres some sniplets:

  UsersTableAdapter uAdapter = new UsersTableAdapter(); 
ItemTableAdapter iAdapter = new ItemTableAdapter();

用户选择:

  SELECT ID,name,password,sold,isLogged,lastLog FROM dbo.Users 

项目选择:

  SELECT Id,name,sale_price,min_price,cog FROM dbo.Item 

两者都使用相同的连接字符串:

  Data Source =(LocalDB)\v11.0; AttachDbFilename = | DataDirectory | \ons_data.mdf; Integrated Security = True; Connect Timeout = 30 

另请注意,在Dataset设计器中,适配器工作正常,它成功选择。错误只发生在代码中。



架构的图像:





可能是什么原因?

$ b $好吧,这很奇怪,我通过简单地改变数据库资源管理器的视图来解决这个问题,发现应用程序在UI(数据集设计器)中使用了两个数据库)它使用我的原始数据库,而在代码中,它使用相同的数据库(但是过时,因为我通过数据集设计器更改了它)被复制到调试文件夹,因此仅包含用户表并导致错误


I'm kind of new to C# and am trying out the convenient looking adaper-dataset combo with local database. while I was amazed at how easy and useful it was I stumbled upon an issue:

Whenever I try to fill the Item table with the adapter I get Invalid object name SQLexception, I use the same Dataset for all my tables, dsOns.Users / dsOns.Items. The problem is, the users adapter does recognize and successfully works with Users database(dbo.Users) while the items adapter cannot find the table(dbo.Item).

Heres some sniplets:

    UsersTableAdapter uAdapter = new UsersTableAdapter();
    ItemTableAdapter iAdapter = new ItemTableAdapter();

Users select:

SELECT Id, name, password, sold, isLogged, lastLog FROM dbo.Users

Item select:

SELECT Id, name, sale_price, min_price, cog FROM dbo.Item

Both use the same connection string:

Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\ons_data.mdf;Integrated Security=True;Connect Timeout=30

Also note that in Dataset designer, the adapter works fine, it selects successfully. The error only occurs in code.

Image of the schema:

What could possibly cause this?

解决方案

Okay that was weird, I solved it by simply changing the view of the database explorer, to find that the app uses two databases, in UI(dataset designer) it uses my original db, while in code it uses the same db(but outdated since I changed it via dataset designer) that was copied to debug folder, hence containing only Users table alone and resulting in the error

这篇关于无效的对象名称“dbo.Item”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆