DataAdapter.Fill 方法 查询中有两个表
这可能看起来很简单,但是当我的查询包含多个表时,我很难弄清楚如何填充我的数据集。
例如,如果我有一个查询“SELECT USER_ID, USER_NAME, CREDENTIALS FROM USERS, CREDENTIALS WHERE USER_ID = CRED_ID”,然后尝试使用 DataAdapter.Fill 方法,它会抛出错误并指出它不是单个组函数。
我的 DataAdapter 是 = da
我的数据集是= ds
我正在尝试的是:
da.Fill(ds, "USERS;CREDENTIALS");
或者
da.Fill(ds, "USERS, CREDENTIALS");
我将如何正确地执行此操作? 我只需要运行一个查询,根据匹配的 ID 从 2 个表中进行选择,但我希望它在一个数据集中,这样我就可以浏览结果 1 行和 1 行。一次列。
非常感谢任何帮助!
This may seem simple, but I'm having difficulty figuring out how to fill my dataset when my query includes more than one table.
For example, if I had a query that was "SELECT USER_ID, USER_NAME, CREDENTIALS FROM USERS, CREDENTIALS WHERE USER_ID = CRED_ID" and then try to use the DataAdapter.Fill method it throws and error saying it's not a single group function.
My DataAdapter is = da
My DataSet is = ds
What I'm trying is:
da.Fill(ds, "USERS;CREDENTIALS");
or
da.Fill(ds, "USERS, CREDENTIALS");
How would I go about doing this correctly?
I just need to run a query that selects from 2 tables based on a matching ID, but I'd like it in a single Dataset so I can go through the results 1 row & column at a time.
Any help is GREATLY appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很困惑。您返回的结果是一个“表”。当然,您正在两个表之间进行联接,但您实际上并没有返回两个表。我有什么遗漏的吗?
I'm confused. The result you are getting back is a single "table". You are doing a join between two tables, sure, but you are not actually returning two tables. Is there something I am missing?
问题解决了。
我在查询中执行了 MAX 函数,但没有在 GROUP BY 子句中列出所有 SELECT 字段。
添加这些字段并使其正常工作。
感谢大家!
Problem solved.
I had a MAX function being performed in my query and I did not have all SELECT fields listed in the GROUP BY clause.
Added those fields and got it working.
Thanks to all!