| | |
Problems with parameters and selectcommand
Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 56
Reputation:
Solved Threads: 1
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:
I know it probably looks lame, but the simple 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!
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:
MS SQL Syntax (Toggle Plain Text)
SELECT * FROM (SELECT table_name FROM information_schema.TABLES WHERE table_name= @table_name)
I know it probably looks lame, but the simple
MS SQL Syntax (Toggle Plain Text)
SELECT * FROM @table_name
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!
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
is the first one in a stored procedure? where you pass @table_name in?
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Feb 2008
Posts: 42
Reputation:
Solved Threads: 13
change your command into:
change your second command into:
MS SQL Syntax (Toggle Plain Text)
SELECT * FROM (SELECT table_name FROM information_schema.TABLES WHERE table_name= @table_name ) AliasName
change your second command into:
MS SQL Syntax (Toggle Plain Text)
declare @table_name varchar(255) SELECT @table_name = 'sysdatabases' exec ('select * from ' + @table_name)
Hence Wijaya
www.ex-Soft.tk
www.ex-Soft.tk
![]() |
Similar Threads
- need help (VB.NET)
Other Threads in the MS SQL Forum
- Previous Thread: ms sql
- Next Thread: My zipcode query is not returning the correct results
| Thread Tools | Search this Thread |






