Solved

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

Posted on 2008-10-07
5
981 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 50 total points
ID: 22658247
check out objectdatasource..
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 50 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 400 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now