We help IT Professionals succeed at work.

Create an SQL Temporary Table in VB.Net

Last Modified: 2012-05-08
I need to create a temporary table in SQL (#results) That I can then bind to a Listview to display the results a a search that will be persistant for as long as the user is logged in.  The search results fields willl vary dependant on the criteria, and the query SQL will be build up depending on the criteria, so I need to programmatically create the temporary table, populate it and then bind it to the listview.  
Clearly, static tables are no good, as different users will be searching on different things at the same time.  I know how to create temporary table in SQL natively, but need some help to create them dynamically in VBH.net.  
I don't think stored procedures are the solution either as every query will be slightly different.

Any help would be much appreciated.
Watch Question

Dirk HaestProject manager

If you create the query and run it on your database, just populate a datatable in your code. Then it's also a temporary table
Most Valuable Expert 2012
Top Expert 2014
This one is on us!
(Get your first solution completely free - no credit card required)


Thanks great answer!  I really should have thought of that!!  I got my mind set on temp tables, and missed the obvious.  The solution is great, thanks.
Dirk HaestProject manager

Next time try to be honest with the points and if you accept an answer that's the same as another comment (with some more info), the least you can do is to split the points (give more points to the item you find the most usefull)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.