Solved

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

Posted on 2008-10-07
5
1,041 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 13

Assisted Solution

by:SameerJagdale
SameerJagdale earned 50 total points
ID: 22658247
check out objectdatasource..
0
 
LVL 60

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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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