Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gridview select clause, passing parameter. 1

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
US
Hi,
(ASP.net 2.0)
I have a gridview select statement as such

SelectCommand="SELECT * FROM ABFS ORDER BY [indx]"

I added a select parameter

<code>
<SelectParameters>
<asp:QueryStringParameter QueryStringField="tbl" Name="tbl" Type="object" /> ' even tried type of string
</SelectParameters>
</code>

I modified the select clause as such.

SelectCommand="SELECT * FROM [@tbl] ORDER BY [indx]"


I want to be able to pass in a querystring value as the table name will change.

The error I get is: Invalid object name '@tbl'.

Any Ideas.

Thanks
 
you can't use the parameter as a table the parameter is explict to the where clause. if you want to dynamically select from a table you need to replace the SelectText with each request.

as a side note I this is a gross misuse of the gridview/datasource control.
1. your exposing your db structure to the GUI. the gui shouldn't have any knowledge of the database.
2. your assuming the database has an [indx] column. this may be the case now, but moving forward this may change.
3. selelct * is the most ineffecient way to select data from table(s). explicitly listing the columns is faster and limits the amount of data returned when the db schema changes.
4. you have a scenario where one control does all the work. I would highly recomend spliting this out into seperate forms/user controls and using each one for a specific purpose this also allows for custom formatting for each grid.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi Jason

"the parameter is explict to the where clause" is what is was looking for. Thanks.

The rest I am actually aware of. Right now I'm just experimenting with the gridview. All the checks and balances and appropriate precautions will be in place once I decide on which way I'm going to go.

Thanks Again


-dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top