0

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

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by squirell
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

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
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.