954,577 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SQLAdapter - reading a value from the querystring

Hi,

This is my first post on this forum. Apologies in advance if this isn' the right place or there isn't enough info.

I'm basically trying to retreive an ID from a quesry string...

xyz/nuts.aspx?nuttype=7

What I'm having trouble with is defining the variable and referencing the querystring in the SQL select statement i.e.

"select * from tblNuts where fldNutType = @nuttype"

This is the working code below...

Function getTheData() As DataTable
	Dim DS As New DataSet()		
	Dim strConnect As New SQLConnection	("Server=credentials")
	Dim objSQLAdapter As New SQLDataAdapter("SELECT * FROM tblnuts", strConnect)
	objSQLAdapter.Fill(DS, "tblNuts")
	
	Return DS.Tables("tblNuts").Copy
End Function

Many thanks in advance

squirell
Newbie Poster
7 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

After reading my post what I am looking is for someone to show me how to add a variable in to the SQL satement above.

Thanks again

squirell
Newbie Poster
7 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

Is this what you are looking for

Function getTheData() As DataTable
	Dim DS As New DataSet()		
	Dim strConnect As New SQLConnection	("Server=credentials")
        Dim nutType As String
        Dim selectCmd As String
       'Reads the query string value into the string
        nutType = Request.QueryString("nuttype").ToString(); 
        selectCmd = "SELECT * FROM tblnuts WHERE nuttype = " &  nutType 
	Dim objSQLAdapter As New SQLDataAdapter(selectCmd, strConnect)

	objSQLAdapter.Fill(DS, "tblNuts")
	
	Return DS.Tables("tblNuts").Copy
End Function
Aneesh_Argent
Junior Poster
104 posts since Dec 2008
Reputation Points: 16
Solved Threads: 18
 

Brilliant! Thank you Aneesh, you are a legend!

squirell
Newbie Poster
7 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You