Solved

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

Posted on 2008-10-07
5
993 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
scanning dentists xray (the small ones) 3 45
Not showing JavaScript in the list 5 40
Run time Error 4 35
Vb. Net application freezes 9 31
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

19 Experts available now in Live!

Get 1:1 Help Now