Ask a Question related to ASP Components, Design and Development.
-
rikesh #1
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
-
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,... -
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... -
& 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 & in a string... -
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... -
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,... -
rikesh #2
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
-
Johnd #3
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
-
rikesh #4
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...add> 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 tofilter> 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, tothe> > the recordset.
> > I've got a textbox on the form, and I hoping tot take the string fromparameters.> > 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>> > 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



Reply With Quote

