SQL 中同一列名的多个值

发布于 2024-10-04 16:19:59 字数 305 浏览 8 评论 0原文

这似乎是一个奇怪的问题,之前我通过会话变量发布了关于 ASP 多个值的另一个问题,现在我已经弄清楚了这一点,并设法将所有三个值传递给标签。然而现在我需要传递三个 ID 来为这三个值创建一个 gridview...所以对于我的 SQL 语句我有:

SelectCommand="SELECT [BookID], [book_title] FROM [tblBook] WHERE ([BookID ] = ?)">

所以我需要有 3 个 BookID=?,?,?例如,这可能吗?

或者有其他方法可以在ASP中实现吗?

this might seem like a weird question, earlier I posted another question on ASP multiple values through a session variable, I've now figured that out and have managed to pass all three values for instance to a label. Now however I need to pass the three IDs to create a gridview for the three values... So for my SQL statement I have:

SelectCommand="SELECT [BookID], [book_title] FROM [tblBook] WHERE ([BookID] = ?)">

So I need there to be 3 BookID=?,?,? for instance, is this possible?

Or is there another way to do it in ASP?

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

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

发布评论

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

评论(3

不羁少年 2024-10-11 16:19:59

我认为你正在寻找的是这样的:

SELECT [BookID], [book_title] FROM [tblBook] WHERE [BookID] in (?,?,?)

i think what you're looking for is something like this:

SELECT [BookID], [book_title] FROM [tblBook] WHERE [BookID] in (?,?,?)
玩物 2024-10-11 16:19:59

在 SQL 中,您可以使用“IN”运算符来执行此操作。 SQL 查询将是

SELECT [BookID], [book_title] FROM [tblBook] WHERE [BookID] IN (@Book1,@Book2,@Book3)

您必须将 book1,2,3 作为参数传递给 asp 函数。您可能必须通过附加参数来动态构造查询。像这样的东西

string query = string.Format("SELECT [BookID], [book_title] FROM [tblBook] WHERE [BookID] IN ({0},{1},{2})",book1,book2,book3)

In SQL, you can use the 'IN' operator to do it. The SQL query would be

SELECT [BookID], [book_title] FROM [tblBook] WHERE [BookID] IN (@Book1,@Book2,@Book3)

You will have to pass the book1,2,3 as parameters to the asp function. You might have to construct the query dynamically by appending the parameters. Something like this

string query = string.Format("SELECT [BookID], [book_title] FROM [tblBook] WHERE [BookID] IN ({0},{1},{2})",book1,book2,book3)
满栀 2024-10-11 16:19:59

我不确定你的问题,但我认为你正在寻找 IN 语句

SelectCommand="SELECT [BookID], [book_title] FROM [tblBook] WHERE ([BookID] in (1,2,3)">

I'm not certain by your question, but I think you're after an IN statement

SelectCommand="SELECT [BookID], [book_title] FROM [tblBook] WHERE ([BookID] in (1,2,3)">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文