在一个请求中获取多组数据?

发布于 2024-10-10 14:04:34 字数 218 浏览 0 评论 0原文

我正在一个网站上工作,当用户登录(第一个数据库请求)时,存储过程会验证密码和用户 ID,然后返回我放入会话中以供下一步使用的用户记录。

之后我做了第二个数据库请求。它返回我放入缓存中的用户地址。

您能否指导我是否有某种方法可以在一个数据库请求中获取两组数据(用户记录及其第二个表中的地址)。

请指导我,我正在使用 DAAB(​​输入奖库)进行数据访问。

谢谢

I am working on a site in which as user logs in (first database request) the stored procedure varify password and user id and then returns user record that I put in session to use next.

After this I do a second db request. it returns addresses of user which I put in cache.

Can you pleas guide me is there some way that I can get both sets of data (user record and his address from 2nd table) in one database requests.

plz guide me on this, I am using DAAB (enter prise library) for data access.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌生 2024-10-17 14:04:34

修改具有多个 select 语句的 SP,如您的情况是 2。一个 SP 中的两个 select 语句将返回两个记录集。在 SQL Management Studio 中验证,当您运行 SP 时,它应该在底部面板中显示多个网格。

SP 完成后,从 C# 代码调用 SP 并将结果加载到 DataSet 中。数据集将有两个表,您可以从不同的表中获取数据

Modify your SP which has multiple select statements, as in you case is 2. Two select statements in one SP will return two record sets. Verify in SQL Management Studio, when you run your SP, it should show you multiple Grid in bottom panel.

Once your SP is done, call SP from C# code and load result in DataSet. Dataset will have two table, and you can get the data from different table

昇り龍 2024-10-17 14:04:34

您可以在存储过程中编写两个选择查询或
依次执行两个查询。在单个查询中,您可以执行并接收 DataSet 中的数据。

ExecuteDataset()

因此数据集中将返回两个表。您可以获得像

dataset.tables(0) 这样的值
数据集.tables(1)

谢谢

You can write two select queries in a stored procedure or
Execute two queries one after another . In single query you can execute and receive the data in DataSet .

ExecuteDataset()

So two tables will be returned inside the dataset . You can get the values like

dataset.tables(0)
dataset.tables(1)

Thanks

转瞬即逝 2024-10-17 14:04:34

一次性检索两个结果集不会给你带来任何好处,但代码会变得更加不连贯。为什么您认为需要将两个逻辑上独立的操作合并为一个?您可以使用 join 一次性获得包含所有数据的一个结果集,而不是使用此类有问题的方法,但这似乎仍然是错误的。我看不到一种干净的方式来完成您所要求的事情以及可能获得的任何好处。

You would gain nothing from retrieving two results sets in one go, But the code will become more incoherent. Why do you thing you need to merge two logically separate operations into one? Instead of using such questionable methods you can use join to get one result set that contains all the data in one go, but still that seems wrong. I can not see a clean way of doing what you are asking for and any benefits that might be gained.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文