Select depending on Session() value

C

Carlos Albert

Hello everybody,

I have a gridview, and the SelectCommand should change depending on a
Session value.
Not the WHERE, but the field that it retrieves. It goes like this:

SELECT NAME, COST, CATEGORY(###) AS CATEGORY FROM TABLE

Where Category can be Category1, Category2, etc, etc, etc, and I have the
little number in a Session. I tried to put in in some hidden textbox,
variable, anything, but can't make it work.

Would anybody give me some help? ^^
 
A

agapeton

I'm not sure I understand the question, do you mean this?

adapter.SelectCommand = "select name, cost, category(" +
Session["Taco"] + ") as category from table";
adapter.Fill(dataTable);
gvData.DataSource = dataTable;
gvData.DataBind( );

?
 
C

Carlos Albert

Hi, no, I mean this:

<asp:SqlDataSource ID="SqlDataSourceSCPADITE" runat="server"
ConnectionString="<%$ ConnectionStrings:WEBConnectionString %>"
SelectCommand="SELECT name, cost, category1 AS category FROM table">
</asp:SqlDataSource>

Where the "1" in "category1" could be 1 to 9 depending of a session value.
It gave me "The server tag is not well formed" and other errors when I tried
something like
SelectCommand="SELECT name, cost, category<% Session("burrito")%> AS
category FROM table">

Seems I cannot insert some <%server side code%> inside de SelectCommand, but
don't know how to do it otherwise.
 
C

Carlos Albert

Ok, made it work.
I declared a public (string) from the codebehind and generated _ALL_ the
SelectCommand in there.
The I just used SelectCommand="<%# SelectCommand_CAT %>">, now it works.
Seems that it doesn't like to concatenate. Lol.

Tnx everyone.

Carlos Albert said:
Hi, no, I mean this:

<asp:SqlDataSource ID="SqlDataSourceSCPADITE" runat="server"
ConnectionString="<%$ ConnectionStrings:WEBConnectionString %>"
SelectCommand="SELECT name, cost, category1 AS category FROM table">
</asp:SqlDataSource>

Where the "1" in "category1" could be 1 to 9 depending of a session value.
It gave me "The server tag is not well formed" and other errors when I tried
something like
SelectCommand="SELECT name, cost, category<% Session("burrito")%> AS
category FROM table">

Seems I cannot insert some <%server side code%> inside de SelectCommand, but
don't know how to do it otherwise.

I'm not sure I understand the question, do you mean this?

adapter.SelectCommand = "select name, cost, category(" +
Session["Taco"] + ") as category from table";
adapter.Fill(dataTable);
gvData.DataSource = dataTable;
gvData.DataBind( );

?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top