Improve company productivity with a Business Account.Sign Up

x
?
Solved

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

Posted on 2008-10-07
5
Medium Priority
?
1,068 Views
Last Modified: 2012-05-05
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
Comment
Question by:pythonV
5 Comments
 
LVL 13

Assisted Solution

by:SameerJagdale
SameerJagdale earned 200 total points
ID: 22658247
check out objectdatasource..
0
 
LVL 61

Assisted Solution

by:Kevin Cross
Kevin Cross earned 200 total points
ID: 22658251
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
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 1600 total points
ID: 22658339
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
 

Author Comment

by:pythonV
ID: 22658516
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
 

Author Comment

by:pythonV
ID: 22658913
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
To export Lotus Notes to Outlook PST or Exchange and Domino Server files to Exchange Server or PST files with ease, go for Kernel for Lotus Notes to Outlook conversion tool. Through the video, you can watch the conversion process. A common user with…
Did you know PowerShell can save you time with SaaS platforms? Simply leverage RESTfulAPIs to build your own PowerShell modules. These will kill repetitive tickets and tabs, using the command Invoke-RestMethod. Tune into this webinar to learn how…

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question