Problems with parameters and selectcommand

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2008
Posts: 56
Reputation: konczuras is an unknown quantity at this point 
Solved Threads: 1
konczuras konczuras is offline Offline
Junior Poster in Training

Problems with parameters and selectcommand

 
0
  #1
Nov 18th, 2008
Hello Everybody!

I have the following problem: I want to make an application, which need tables to show, edit, etc. You would be able to select the table, which you want to work on, by a dropdownlist (the whole project is in ASP.NET). I want to load the selected table's data to a gridview, and I desperately need a selectcommand for it.
I have succesfully retreived the name of the table, which is selected in the dropdownlist, with a sqlparameter, but can't use it in my selectcommand. The code is the following:

  1. SELECT * FROM (SELECT table_name
  2. FROM information_schema.TABLES
  3. WHERE table_name= @table_name)

I know it probably looks lame, but the simple
  1. SELECT * FROM @table_name
refused to work too.

To the first one, I get the error message "incorrect syntax near ')'
For the second, it tells me that I must declare the table variable, but I have no idea, how to link it with the dropdownlist.

I thank you forwardly to your help!
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Problems with parameters and selectcommand

 
0
  #2
Nov 18th, 2008
is the first one in a stored procedure? where you pass @table_name in?
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 42
Reputation: huangzhi is an unknown quantity at this point 
Solved Threads: 13
huangzhi huangzhi is offline Offline
Light Poster

Re: Problems with parameters and selectcommand

 
0
  #3
Nov 19th, 2008
change your command into:
  1. SELECT *
  2. FROM (SELECT table_name
  3. FROM information_schema.TABLES
  4. WHERE table_name= @table_name
  5. ) AliasName

change your second command into:
  1. declare @table_name varchar(255)
  2. SELECT @table_name = 'sysdatabases'
  3. exec ('select * from ' + @table_name)
Hence Wijaya
www.ex-Soft.tk
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 56
Reputation: konczuras is an unknown quantity at this point 
Solved Threads: 1
konczuras konczuras is offline Offline
Junior Poster in Training

Re: Problems with parameters and selectcommand

 
0
  #4
Nov 19th, 2008
Thank you for your help, but it still don't works. The first code ignores the 'select * from' from the beginning, and just displays the table name.
The second tells me that the table_name variable is duplicate, so it can't perform it's task.

Any idea, how could I solve this?

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 56
Reputation: konczuras is an unknown quantity at this point 
Solved Threads: 1
konczuras konczuras is offline Offline
Junior Poster in Training

Re: Problems with parameters and selectcommand

 
0
  #5
Nov 19th, 2008
I've figured it out, I used some coding in C#, and it works perfectly, thank you very much.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC