Announcement

Collapse
No announcement yet.

SQL query through ASP

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL query through ASP

    Not sure if this is the right forum but I'll try.

    I have an SQL DB. I need to create a simple web form to query that DB.

    the DB holds stuff like username password etc... and i need to be able to enter any of the fields in order to return all possible data on the users that have that info...

    Looking for sources on the web on it and can't find anything concrete.

    Anyone got anything???

    Thanks.
    Visit iCount
    Visit MSEC
    Visit LCS-GUIDES.COM
    Visit Melariche

  • #2
    There's more than one way to do it. Read this article (with code examples) to get an idea of how to do it. If you still need more help afterwards I'll help you out with code.

    http://www.devarticles.com/c/a/ASP/T...-2000-Via-ASP/
    Andrew

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    Comment


    • #3
      That helps.
      But moving on from there to creating an actual query is something i still don't get...

      Any ideas on that?
      Visit iCount
      Visit MSEC
      Visit LCS-GUIDES.COM
      Visit Melariche

      Comment


      • #4
        Once you have the connection setup correctly and can connect you can create a record set to store data for manipulation. To use it you connect to the record set and send as a parameter the SQL query, and the connection string. This will fill the record set with the return data of the query. Here's some code as an example:

        Code:
        <%
        Dim strCon
        Dim strSQL
        Dim objCustomers
        
        Set strCon = Server.CreateObject("ADODB.Connection")
        strCon.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = Northwind; User Id = sa; Password="
        
        Set objCustomers = Server.CreateObject("ADODB.Recordset")
        strSQL = "SELECT * FROM Customers;"
        
        objCustomers.Open strSQL, strCon
        Now you have a record set of all the data and can loop thru its contents, like the following:

        Code:
        Do While not objCustomers.EOF
        	          
             Response.Write ("<br>")
             Response.Write (objCustomers("ColumnName"))
             Response.Write ("<br>")
             Response.Write (objCustomers("ColumnName"))
             Response.Write ("<br>")
             Response.Write (etc ...)
        
             objCustomers.MoveNext
        
        Loop
        Don't forget to close the DB connection, otherwise you'll get errors stating that the connection is already open.

        Code:
        objCustomers.Close
        strCon.Close
        Set objCustomers = Nothing
        Set strCon = Nothing
        %>
        Remember: This is psuedo code. It is quite likely that it will not work for you until you have edited it to meet your needs. I have not tested this code so it may not work, its just to give you an idea of how to do it.
        Andrew

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        Comment

        Working...
        X