使用 SQL #tempdb 将 databind() 绑定到 ListBox

发布于 2024-11-26 21:37:00 字数 348 浏览 0 评论 0原文

我正在创建一个网页,其中有一系列对ListBoxes。每对都有一个源(包含许多选项),您可以在其中选择一个选项(或多个)并将其添加到第二个列表框。

我创建了一些永久表,其中包含源列表框的静态成员;但是,我想使用“SELECT * INTO #tempsrc1 FROM src1”,然后将#tempsrc1绑定到ListBox。从那里将为目标列表框绑定创建#tempdst1。然后任何选择都会相应地从那里来回移动。

虽然绑定到永久数据库很容易,但我在绑定到 #tempdb 设置的其余部分中遇到了麻烦(如果可能的话),我对 SQL 很陌生,并且对该体系结构没有深入的了解。

I am creating a webpage in which I have a series of pairs ListBoxes. In each pair there is a source (containing many options) in which you can then select an option (or multiple) and add it to the second listbox.

I have some permanent tables created which contain the static members for the source listboxes; however, I would like to use a "SELECT * INTO #tempsrc1 FROM src1" and then bind the #tempsrc1 to ListBox. From there a #tempdst1 would be created for the destination ListBox binding. Then any selections would just be moved back and forth from there accordingly.

While binding to permanent databases is easy enough, I am having trouble (if its even possible) binding to the #tempdb setup for the rest of this, I am quite new to SQL and do not have a solid understanding of the architecture.

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

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

发布评论

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

评论(4

旧故 2024-12-03 21:37:00

我认为你的设计是错误的。

临时数据不应该保存在数据库中,而应该保存在应用程序层中。在有两个列表框的情况下,您可能可以使用列表框本身来跟踪项目。如果您需要保留与列表框中显示的文本相关的数据,我建议在 Session 对象中放置一个 Dictionary

在可能使用不同数据库连接的不同请求之间保持 #temptable 处于活动状态也可能很棘手。除非你将数据库连接存储在Session中,我认为当连接池重置数据库连接时#temptables将会丢失。

I think that your design is wrong.

Temporary data should not be kept in the database, but in the application layer. In the case with two listboxes you are probably able to use the listboxes themselves to keep track of the items. If you need to keep data that is related to the text displayed in the listboxes I'd recommend putting a Dictionary<> in the Session object.

Keeping a #temptable alive between different requests which will probably be utilizing different database connections might be tricky too. Unless you store the database connection in Session I think that the #temptables will be lost when the connection pool resets the database connection.

往日情怀 2024-12-03 21:37:00

我建议不要使用临时数据库。因为新连接可能会丢失该值。如果需要,请使用永久表并将列表框数据放入缓存中。

I would suggest not to use the temp db. As the value might get lost with the new connection. Use the permanent tables and put the listbox data in cache if needed.

蓝天白云 2024-12-03 21:37:00

源列表框有一个 selectedindexchanged 事件。

使用该事件来:
1) 创建一个列表框项目
2) 设置列表框项 = 源的选定项
3) items.add 或 items.insert 将列表框项目添加到目标列表框。

这是非常标准的。但不要在数据库中使用临时表。正如@Andres 所说,在应用程序层中进行跟踪。 In 可以想到的唯一例外是您是否需要跟踪会话范围之外的情况。

Source Listbox has a selectedindexchanged event.

Use that event to:
1) create a listbox item
2) set listbox item = the selected item of the source
3) items.add or items.insert the listbox item to your destination listbox.

This is pretty standard. But do not use a temp table in the database. As @Andres says, keep track in your application layer. The only exception In can think of is if you need to keep track beyond the scope of the session.

阳光①夏 2024-12-03 21:37:00

我在使用 winforms 应用程序的临时表时遇到了同样的问题。您的应用程序需要绑定到永久表,不能绑定到存储在 SQL Server 中的临时表。

您可以创建一个存储过程来返回所需的数据。

I ran into this same issue with working with a temp table for a winforms application. Your application needs to be bound to a permanent table, you cannot bind to a temp table that is stored in SQL server.

You can create a stored procedure that will return the data that you want.

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