使用SQL #tempdb将databind()应用到ListBox

时间:2022-02-05 16:17:21

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.

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

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.

虽然绑定到永久数据库很容易,但在接下来的工作中,我很难(如果可能的话)绑定到#tempdb设置,我对SQL很不熟悉,对体系结构也不是很了解。

4 个解决方案

#1


1  

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.

在可能使用不同数据库连接的不同请求之间保持一个#temptable,可能也很棘手。除非您将数据库连接存储在会话中,否则我认为当连接池重置数据库连接时,#temptables将丢失。

#2


1  

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.

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

#3


1  

Source Listbox has a selectedindexchanged event.

源列表框有一个selectedindexchanged事件。

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.

使用该事件:1)创建listbox项目2)设置listbox项=源3的选定项。添加或物品。将列表框项插入到目标列表框中。

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.

这是非常标准的。但是不要在数据库中使用临时表。正如@Andres所说,在应用程序层中保持跟踪。惟一的例外是,如果您需要跟踪会话范围之外的内容。

#4


0  

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.

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

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

您可以创建一个存储过程,该过程将返回您想要的数据。

#1


1  

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.

在可能使用不同数据库连接的不同请求之间保持一个#temptable,可能也很棘手。除非您将数据库连接存储在会话中,否则我认为当连接池重置数据库连接时,#temptables将丢失。

#2


1  

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.

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

#3


1  

Source Listbox has a selectedindexchanged event.

源列表框有一个selectedindexchanged事件。

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.

使用该事件:1)创建listbox项目2)设置listbox项=源3的选定项。添加或物品。将列表框项插入到目标列表框中。

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.

这是非常标准的。但是不要在数据库中使用临时表。正如@Andres所说,在应用程序层中保持跟踪。惟一的例外是,如果您需要跟踪会话范围之外的内容。

#4


0  

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.

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

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

您可以创建一个存储过程,该过程将返回您想要的数据。