Jump to content

Using URL parameters to search database


Manny

Recommended Posts

Hi there,I'm currently doing a university project in ASP.NET and I need to grab a parameter from the end of a URL and use this to perform a database query in MSSQL.An example URL is:myproject.com/courses/?courseid=BCT001I know that by using the following piece of code, the parameter will be printed to the screen.

<%=Request.QueryString["courseID"]%>

That is not what I want to do though. I somehow need to store the querystring and use it to search the database like in the example below:

SELECT * FROM courses WHERE courseID = <% courseID %>

I've tried searching the web but I can't find anything to help me out. If this was PHP, it'd be done in 2 minutes! :) Any help would be very much appreciated. Very confident with PHP but a newbie to ASP.NET, so please keep it simple.

Link to comment
Share on other sites

  • 1 month later...
Dim MyCommand As New SqlCommand("Select * From MyTable Where MyField = @MyQString", MyConnection)MyCommand.Parameters.Add("@MyQString", SqlDbType.VarChar)MyCommand.Parameters("@MyQString").value = Request.QueryString("courseID")

I'm not really sure about those script because I'm using ADO.NET (OleDbCommand, OleDbConnection, OleDbParameter). You are using MySQL and I think those script should work. Give a try. :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...