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

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

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

Brilliant! Thank you Aneesh, you are a legend!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.