• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1061
  • Last Modified:

How do I call a session variable into a Table adapter SQL query using Query builder

Hello,

I am using ASP.NET with VB and i need to create a gridview which gets data from an SQL query.

For the WHERE condition of the query i need to call a global variable ex. Session("item"), how do i do this using the query builder when creating a new table adapter. I would rather not do it by code.

Any help is appreciated,

Thanks in advance.
0
pythonV
Asked:
pythonV
3 Solutions
 
SameerJagdaleCommented:
check out objectdatasource..
0
 
Kevin CrossChief Technology OfficerCommented:
I know you are not looking for a code behind solution, but 1) I don't believe that is possible, but that just means I haven't done it before and 2) if you can't, at least you can mitigate the code outside of the query builder by using a parameter and then set the parameter value to Session("Item").

http://aspnet.4guysfromrolla.com/articles/030106-1.aspx
0
 
carlnorrbomCommented:
Hi,

Well, I guess the easiest way is to do the following, in the dataset designer when creating your query, just declare the parameter (@Param) as you would normally do, i.e:

SELECT * FROM Items WHERE (Item = @Item)

Close out the query designer, choose to return a datatable and give it a meaningful name, i.e. GetItemByItemName or similar. Click Next -> Finish and save off the dataset.

In Your IDE, drag and drop a ObjectDataSource onto the page, choose configure datasource and choose the table adapter you just created. Choose the method you created in query designer (GetItemByItemName) and click next.  On the next page in the drop down for parameter source, choose "Session". In the SessionField textbox write "Item" and you will notice in the left view that it says Name = Item and Value = Session("Item"). If needed enter a default value. Click Finish and You're done!

Now you can use the ObjectDataSource you just created and bind to whatever control you need to display the results.

/Carl.
0
 
pythonVAuthor Commented:
Many Thanks for the response it solved my problem, however I may have another one.

I am databinding to a gridview, for some reason the gridview is not appearing on the page.

Any ideas?

Thanks for your help.
0
 
pythonVAuthor Commented:
Just realised that a new change in the query resulted in not getting any fields returned.

I need to rethink the query but in terms of passing the parameters all is well.

Thanks for your help.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now