Answered by:
How to Fetch Rows based on Values in a Session Variable ?

Question
-
User1347510516 posted
Hi,I am storing some values in a Session on one page. On the next page, I want to fetch rows from the Database and display in a Datalist or Gridview based upon the values in this session. The session may contain any number of values. I think I need to send session values to a Select Statment using some loop, but I don't know how to do it ? Can anyone plz help with source code ?ThanksHi,
I am storing some values in a "Session" on one page. On the next page, I want to fetch rows from the Database and display in a Datalist or Gridview based upon the values in this "Session". The session may contain any "Number" of Values (1,5,7,10 ......). These values are basically codes like A110, A120, A119 .... etc
So I need to generate a "Select" Statement dynamically (like the example below) using Values in a Session variable, but I don't know how to do it ?
Select * from Design_Codes where Code = 'A110' AND Code = 'A120' AND Code = ...................
Can anyone plz help with source code ?
Thanks
Thursday, December 23, 2010 2:11 PM
Answers
-
User1898118805 posted
I am trying to populate a dropdown list from an Oracle database tables, but I have similar challenges passing a session variable onto a SelectCommand
Part of the code reads:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:oraDB %>" ProviderName="<%$ ConnectionStrings:oraDB.ProviderName %>" SelectCommand="SELECT distinct bu.bu_id FROM bu WHERE bu.bu_id = Session["bu_id"]"
Session["bu_id"] is created when a user login.
I will appreciate any help on how to achieve this.
Also note that I have tried the following codes but the dropdownlist isn't populated and no any error shown.
SelectCommand="SELECT distinct bu.bu_id FROM bu WHERE bu.bu_id = @BU_ID"
<SelectParameters>
<asp:SessionParameter Name="BU_ID" SessionField="Session['UserBUID']" />
</SelectParameters>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, December 24, 2010 7:00 AM
All replies
-
User1955095561 posted
You can generate an array of the values like this
string s = Session["abdcdcd"].ToString();
string[] sArr = s.Split(new char[',']);then iterate through the 'sArr'
Thursday, December 23, 2010 5:25 PM -
User1347510516 posted
You can generate an array of the values like this
string s = Session["abdcdcd"].ToString();
string[] sArr = s.Split(new char[',']);then iterate through the 'sArr'
How do I construct the "Select" query with your code ?
Friday, December 24, 2010 12:36 AM -
User-1418680850 posted
Hi,
you can generate a select statement like this
Select * from Design_Codes where Code in ('A110' , 'A120',..................)
Friday, December 24, 2010 4:35 AM -
User1898118805 posted
I am trying to populate a dropdown list from an Oracle database tables, but I have similar challenges passing a session variable onto a SelectCommand
Part of the code reads:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:oraDB %>" ProviderName="<%$ ConnectionStrings:oraDB.ProviderName %>" SelectCommand="SELECT distinct bu.bu_id FROM bu WHERE bu.bu_id = Session["bu_id"]"
Session["bu_id"] is created when a user login.
I will appreciate any help on how to achieve this.
Also note that I have tried the following codes but the dropdownlist isn't populated and no any error shown.
SelectCommand="SELECT distinct bu.bu_id FROM bu WHERE bu.bu_id = @BU_ID"
<SelectParameters>
<asp:SessionParameter Name="BU_ID" SessionField="Session['UserBUID']" />
</SelectParameters>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, December 24, 2010 7:00 AM