Pass Param to SQL Query

Ask a Question related to ASP Components, Design and Development.

  1. #1

    Default RE:Pass Param to SQL Query

    Hi

    I'm sure this is very trivial, but I simple don't know how to it?

    I've got a SQL query but I wish to pass a 'WHERE' clause to it, to filter
    the recordset.
    I've got a textbox on the form, and I hoping tot take the string from the
    user and pass it to the SQL string.

    Any help would be much appreciated.

    I have some exmplae code beloew, as an example.

    Kind Regards and many thanks for reading this post.

    Rikesh

    SAMPLE CODE BELOW:


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=unicode">
    <%
    Dim cnnSimple ' ADO connection
    Dim rstSimple ' ADO recordset
    Dim strDBPath ' path to our Access database (*.mdb) file
    Dim strParam ' String from Textbox to pass in to the SQL for parameters.
    Dim strSQL ' String to execute the SQL.

    Set cnnSimple = Server.CreateObject("ADODB.Connection")

    cnnSimple.Open "Provider=sqloledb;" & _
    "Data Source=rpatel;" & _
    "Initial Catalog=pubs;" & _
    "User Id=sa;" & _
    "Password=admin"

    strSQL = "SELECT * FROM Authors"

    Set rstSimple = cnnSimple.Execute(strSQL)


    %>
    <META content="MSHTML 6.00.2800.1276" name=GENERATOR></HEAD>
    <BODY>
    <TABLE title="sample title" style="WIDTH: 647px; HEIGHT: 41px"
    borderColor=royalblue bgColor=#99ccff border=3>
    <%

    Do While Not rstSimple.EOF
    %>
    <TR>
    <TD><%= rstSimple.Fields("au_fname").Value %></TD>
    <TD><%= rstSimple.Fields("au_lname").Value %></TD>
    <TD><%= rstSimple.Fields("Address").Value %></TD>
    <TD><%= rstSimple.Fields("City").Value %></TD>
    <TD><%= rstSimple.Fields("State").Value %></TD>
    </TR>
    <%
    rstSimple.MoveNext
    Loop

    %>
    </TABLE>
    <%
    ' Close our recordset and connection and dispose of the objects
    rstSimple.Close
    Set rstSimple = Nothing
    cnnSimple.Close
    Set cnnSimple = Nothing

    %>

    <INPUT id=text1 style="WIDTH: 315px; HEIGHT: 22px" size=40
    name=text1></BODY></HTML>



    rikesh Guest

  2. Similar Questions and Discussions

    1. Query Param Limit with SQL Server
      We have several reports where users can select a "subset" of users to apply the results to (by selecting a custom-built query). In these reports,...
    2. Can't pass a query out of a custom tag
      I am attempting to extract a query from a custom tag. I am passing several variables into a custom tag using CFMODULE. I then run a query based...
    3. & in a string to pass through url param
      I am trying to add a list/menu in DW2004, and for each option I need to pass url paramerters the problem I am having is concantinating &amp; in a string...
    4. In true, i need to pass a placeholder by param
      Hi again. I'm wrong in my first message. What I need to do is, render my control in a placeholder passed by param. I try somethings here, by I get...
    5. query a DB - pass the query to next page
      I am running a querry on an access database and have set the number of records/page displayed at 20. if there are more than 20 records returned,...
  3. #2

    Default Pass Param to SQL Query

    Hi

    I'm sure this is very trivial, but I simple don't know how to it?

    I've got a SQL query but I wish to pass a 'WHERE' clause to it, to filter
    the recordset.
    I've got a textbox on the form, and I hoping tot take the string from the
    user and pass it to the SQL string.

    Any help would be much appreciated.

    I have some exmplae code beloew, as an example.

    Kind Regards and many thanks for reading this post.

    Rikesh

    SAMPLE CODE BELOW:


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=unicode">
    <%
    Dim cnnSimple ' ADO connection
    Dim rstSimple ' ADO recordset
    Dim strDBPath ' path to our Access database (*.mdb) file
    Dim strParam ' String from Textbox to pass in to the SQL for parameters.
    Dim strSQL ' String to execute the SQL.

    Set cnnSimple = Server.CreateObject("ADODB.Connection")

    cnnSimple.Open "Provider=sqloledb;" & _
    "Data Source=rpatel;" & _
    "Initial Catalog=pubs;" & _
    "User Id=sa;" & _
    "Password=admin"

    strSQL = "SELECT * FROM Authors"

    Set rstSimple = cnnSimple.Execute(strSQL)


    %>
    <META content="MSHTML 6.00.2800.1276" name=GENERATOR></HEAD>
    <BODY>
    <TABLE title="sample title" style="WIDTH: 647px; HEIGHT: 41px"
    borderColor=royalblue bgColor=#99ccff border=3>
    <%

    Do While Not rstSimple.EOF
    %>
    <TR>
    <TD><%= rstSimple.Fields("au_fname").Value %></TD>
    <TD><%= rstSimple.Fields("au_lname").Value %></TD>
    <TD><%= rstSimple.Fields("Address").Value %></TD>
    <TD><%= rstSimple.Fields("City").Value %></TD>
    <TD><%= rstSimple.Fields("State").Value %></TD>
    </TR>
    <%
    rstSimple.MoveNext
    Loop

    %>
    </TABLE>
    <%
    ' Close our recordset and connection and dispose of the objects
    rstSimple.Close
    Set rstSimple = Nothing
    cnnSimple.Close
    Set cnnSimple = Nothing

    %>

    <INPUT id=text1 style="WIDTH: 315px; HEIGHT: 22px" size=40
    name=text1></BODY></HTML>



    rikesh Guest

  4. #3

    Default Re: Pass Param to SQL Query

    Remember that Some of your code is client side and some server. The query
    runs at the serve before serving the page to the client. If you want to add
    a "where" clause, you will need to submit the page back to the server with
    the where clause criteria. Then serve the page to he client again.

    John,

    "rikesh" <rikesh_patel@website.com> wrote in message
    news:Ovh9C6l5DHA.2416@TK2MSFTNGP10.phx.gbl...
    > Hi
    >
    > I'm sure this is very trivial, but I simple don't know how to it?
    >
    > I've got a SQL query but I wish to pass a 'WHERE' clause to it, to filter
    > the recordset.
    > I've got a textbox on the form, and I hoping tot take the string from the
    > user and pass it to the SQL string.
    >
    > Any help would be much appreciated.
    >
    > I have some exmplae code beloew, as an example.
    >
    > Kind Regards and many thanks for reading this post.
    >
    > Rikesh
    >
    > SAMPLE CODE BELOW:
    >
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <HTML><HEAD>
    > <META http-equiv=Content-Type content="text/html; charset=unicode">
    > <%
    > Dim cnnSimple ' ADO connection
    > Dim rstSimple ' ADO recordset
    > Dim strDBPath ' path to our Access database (*.mdb) file
    > Dim strParam ' String from Textbox to pass in to the SQL for parameters.
    > Dim strSQL ' String to execute the SQL.
    >
    > Set cnnSimple = Server.CreateObject("ADODB.Connection")
    >
    > cnnSimple.Open "Provider=sqloledb;" & _
    > "Data Source=rpatel;" & _
    > "Initial Catalog=pubs;" & _
    > "User Id=sa;" & _
    > "Password=admin"
    >
    > strSQL = "SELECT * FROM Authors"
    >
    > Set rstSimple = cnnSimple.Execute(strSQL)
    >
    >
    > %>
    > <META content="MSHTML 6.00.2800.1276" name=GENERATOR></HEAD>
    > <BODY>
    > <TABLE title="sample title" style="WIDTH: 647px; HEIGHT: 41px"
    > borderColor=royalblue bgColor=#99ccff border=3>
    > <%
    >
    > Do While Not rstSimple.EOF
    > %>
    > <TR>
    > <TD><%= rstSimple.Fields("au_fname").Value %></TD>
    > <TD><%= rstSimple.Fields("au_lname").Value %></TD>
    > <TD><%= rstSimple.Fields("Address").Value %></TD>
    > <TD><%= rstSimple.Fields("City").Value %></TD>
    > <TD><%= rstSimple.Fields("State").Value %></TD>
    > </TR>
    > <%
    > rstSimple.MoveNext
    > Loop
    >
    > %>
    > </TABLE>
    > <%
    > ' Close our recordset and connection and dispose of the objects
    > rstSimple.Close
    > Set rstSimple = Nothing
    > cnnSimple.Close
    > Set cnnSimple = Nothing
    >
    > %>
    >
    > <INPUT id=text1 style="WIDTH: 315px; HEIGHT: 22px" size=40
    > name=text1></BODY></HTML>
    >
    >
    >

    Johnd Guest

  5. #4

    Default Re: Pass Param to SQL Query

    Is there a way to not run the server side code and run my client (i.e the
    WHERE clause first) then the server side code?


    "Johnd" <johnjob{a}myway.com> wrote in message
    news:ud6gkno5DHA.2404@TK2MSFTNGP12.phx.gbl...
    > Remember that Some of your code is client side and some server. The query
    > runs at the serve before serving the page to the client. If you want to
    add
    > a "where" clause, you will need to submit the page back to the server with
    > the where clause criteria. Then serve the page to he client again.
    >
    > John,
    >
    > "rikesh" <rikesh_patel@website.com> wrote in message
    > news:Ovh9C6l5DHA.2416@TK2MSFTNGP10.phx.gbl...
    > > Hi
    > >
    > > I'm sure this is very trivial, but I simple don't know how to it?
    > >
    > > I've got a SQL query but I wish to pass a 'WHERE' clause to it, to
    filter
    > > the recordset.
    > > I've got a textbox on the form, and I hoping tot take the string from
    the
    > > user and pass it to the SQL string.
    > >
    > > Any help would be much appreciated.
    > >
    > > I have some exmplae code beloew, as an example.
    > >
    > > Kind Regards and many thanks for reading this post.
    > >
    > > Rikesh
    > >
    > > SAMPLE CODE BELOW:
    > >
    > >
    > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > > <HTML><HEAD>
    > > <META http-equiv=Content-Type content="text/html; charset=unicode">
    > > <%
    > > Dim cnnSimple ' ADO connection
    > > Dim rstSimple ' ADO recordset
    > > Dim strDBPath ' path to our Access database (*.mdb) file
    > > Dim strParam ' String from Textbox to pass in to the SQL for
    parameters.
    > > Dim strSQL ' String to execute the SQL.
    > >
    > > Set cnnSimple = Server.CreateObject("ADODB.Connection")
    > >
    > > cnnSimple.Open "Provider=sqloledb;" & _
    > > "Data Source=rpatel;" & _
    > > "Initial Catalog=pubs;" & _
    > > "User Id=sa;" & _
    > > "Password=admin"
    > >
    > > strSQL = "SELECT * FROM Authors"
    > >
    > > Set rstSimple = cnnSimple.Execute(strSQL)
    > >
    > >
    > > %>
    > > <META content="MSHTML 6.00.2800.1276" name=GENERATOR></HEAD>
    > > <BODY>
    > > <TABLE title="sample title" style="WIDTH: 647px; HEIGHT: 41px"
    > > borderColor=royalblue bgColor=#99ccff border=3>
    > > <%
    > >
    > > Do While Not rstSimple.EOF
    > > %>
    > > <TR>
    > > <TD><%= rstSimple.Fields("au_fname").Value %></TD>
    > > <TD><%= rstSimple.Fields("au_lname").Value %></TD>
    > > <TD><%= rstSimple.Fields("Address").Value %></TD>
    > > <TD><%= rstSimple.Fields("City").Value %></TD>
    > > <TD><%= rstSimple.Fields("State").Value %></TD>
    > > </TR>
    > > <%
    > > rstSimple.MoveNext
    > > Loop
    > >
    > > %>
    > > </TABLE>
    > > <%
    > > ' Close our recordset and connection and dispose of the objects
    > > rstSimple.Close
    > > Set rstSimple = Nothing
    > > cnnSimple.Close
    > > Set cnnSimple = Nothing
    > >
    > > %>
    > >
    > > <INPUT id=text1 style="WIDTH: 315px; HEIGHT: 22px" size=40
    > > name=text1></BODY></HTML>
    > >
    > >
    > >
    >
    >

    rikesh Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139