无效的对象名称“dbo.Item"

Invalid object name #39;dbo.Item#39;(无效的对象名称“dbo.Item)

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

问题描述

我是 C# 的新手,我正在尝试使用本地数据库的方便的 adaper-dataset 组合.虽然我对它的简单和有用感到惊讶,但我偶然发现了一个问题:

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:

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

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).

这里有一些片段:

    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

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

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.

架构图:

什么可能导致这种情况?

What could possibly cause this?

推荐答案

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

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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:无效的对象名称“dbo.Item"

基础教程推荐