Hub3rt
Hub3rt

Reputation: 113

Using a SQL #tempdb to databind() to ListBox

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.

Upvotes: 3

Views: 505

Answers (4)

Chains
Chains

Reputation: 13157

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.

Upvotes: 1

Ankit
Ankit

Reputation: 6654

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.

Upvotes: 1

Taryn
Taryn

Reputation: 247700

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.

Upvotes: 0

Anders Abel
Anders Abel

Reputation: 69260

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.

Upvotes: 1

Related Questions