Jump to content
Manny

Using URL parameters to search database

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.

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...