Invalid object name #39;dbo.Item#39;(无效的对象名称“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"
基础教程推荐
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01