Search Database (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


climberman -> Search Database (1/9/2008 18:18:36)

I am building a search page and don't know enough code to make it do what I want, mine is very simple. I am using an AND but I have tried using OR but the results are pretty much the same. Here is the code for the search
Recordset1.Source = "SELECT * FROM PostPeople WHERE FirstName = '" + Replace(Recordset1__MMColParam, "'", "''") + "' and LastName = '" + Replace(Recordset1__Last, "'", "''") + "' and State = '" + Replace(Recordset1__ST, "'", "''") + "'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

I have 3 fields but if one is blank all the names come up, anyway what is the better way. I read some of the other posts but I can't make any sense of it.

Thanks




rdouglass -> RE: Search Database (1/9/2008 22:30:54)

What I do is to determine if there is criteria *before* generating the SQL code for that field. Something like this I use often:

Dim myCriteria
myCriteria = ""

If Replace(trim(Recordset1__MMColParam&""), "'", "''") > "" Then
myCriteria = "(FirstName = '" + Replace(Recordset1__MMColParam, "'", "''") + "')"
End If

If Replace(trim(Recordset1__Last&""), "'", "''") > "" Then
If myCriteria > ""
'if there is something in myCriteria put the AND clause in
myCriteria = myCriteria & " AND "
End If
myCriteria = myCriteria & "(LastName = '" + Replace(Recordset1__Last, "'", "''") + "')"
End If

If Replace(trim(Recordset1__ST&""), "'", "''") > "" Then
If myCriteria > ""
myCriteria = myCriteria & " AND "
End If
myCriteria = myCriteria & "(State = '" + Replace(Recordset1__ST, "'", "''") + "')"
End If

Recordset1.Source = "SELECT * FROM PostPeople WHERE " & myCriteria
...


This should include the field in the search criteria *only* if there is something in that field.

That's how I do it - something like that. Hope it helps.




climberman -> RE: Search Database (1/10/2008 11:16:52)

When I put the code in I get this error - # Error Type:
Microsoft VBScript compilation (0x800A03F9)
Expected 'Then'
/WebPages/Search.asp, line 38, column 18
If myCriteria > ""
-----------------^
I understand some of the code but what is myCriteria? Do I need to replace that with what ever my criteria is?




Spooky -> RE: Search Database (1/10/2008 13:16:58)

Youll need to place the 'then' that Roger forgot in those 2 lines :)

If myCriteria > "" then

Remember though, its only an example that youll need to understand and edit




rdouglass -> RE: Search Database (1/10/2008 15:58:37)

quote:

Youll need to place the 'then' that Roger forgot in those 2 lines :)

If myCriteria > "" then


Ooops! [&o] Thanks for the catch.




climberman -> RE: Search Database (1/10/2008 18:31:04)

Right now if I leave a field blank no one comes up.


(EDIT: Somehow I edited your post by mistake. Sorry.[&o])




rdouglass -> RE: Search Database (1/11/2008 8:43:33)

quote:

Right now if I leave a field blank no one comes up.


It shouldn't. Can you post the code you have running on your page?




climberman -> RE: Search Database (1/11/2008 9:58:51)

It works great but if I type in last name and other fields are blank nothing comes up and if I type in state and nothing else nothing comes up but if I type in first name that comes up. I tried changing to (and) that helped. In the code I sent there might be some (and) and (or)'s. I can't remember where I left off. Thanks!

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/reputation.asp" -->
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.Form("FirstName") <> "") Then 
  Recordset1__MMColParam = Request.Form("FirstName")
End If
%>
<%
Dim Recordset1__Last
Recordset1__Last = "2"
If (Request.Form("LastName")   <> "") Then 
  Recordset1__Last = Request.Form("LastName")  
End If
%>
<%
Dim Recordset1__ST
Recordset1__ST = "3"
If (Request.Form("State")  <> "") Then 
  Recordset1__ST = Request.Form("State") 
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_reputation_STRING
Dim myCriteria
myCriteria = ""

If Replace(trim(Recordset1__MMColParam&""), "'", "''") > "" Then
myCriteria = "(FirstName = '" + Replace(Recordset1__MMColParam, "'", "''") + "')"
End If

If Replace(trim(Recordset1__Last&""), "'", "''") > "" Then
If myCriteria > "" then
'if there is something in myCriteria put the AND clause in
myCriteria = myCriteria & " and "
End If
myCriteria = myCriteria & "(LastName = '" + Replace(Recordset1__Last, "'", "''") + "')"
End If

If Replace(trim(Recordset1__ST&""), "'", "''") > "" Then
If myCriteria > "" then
myCriteria = myCriteria & " or "
End If
myCriteria = myCriteria & "(State = '" + Replace(Recordset1__ST, "'", "''") + "')"
End If

Recordset1.Source = "SELECT * FROM PostPeople WHERE " & myCriteria
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<%
'  *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

Dim Recordset1_total
Dim Recordset1_first
Dim Recordset1_last

' set the record count
Recordset1_total = Recordset1.RecordCount

' set the number of rows displayed on this page
If (Recordset1_numRows < 0) Then
  Recordset1_numRows = Recordset1_total
Elseif (Recordset1_numRows = 0) Then
  Recordset1_numRows = 1
End If

' set the first and last displayed record
Recordset1_first = 1
Recordset1_last  = Recordset1_first + Recordset1_numRows - 1

' if we have the correct record count, check the other stats
If (Recordset1_total <> -1) Then
  If (Recordset1_first > Recordset1_total) Then
    Recordset1_first = Recordset1_total
  End If
  If (Recordset1_last > Recordset1_total) Then
    Recordset1_last = Recordset1_total
  End If
  If (Recordset1_numRows > Recordset1_total) Then
    Recordset1_numRows = Recordset1_total
  End If
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them

If (Recordset1_total = -1) Then

  ' count the total records by iterating through the recordset
  Recordset1_total=0
  While (Not Recordset1.EOF)
    Recordset1_total = Recordset1_total + 1
    Recordset1.MoveNext
  Wend

  ' reset the cursor to the beginning
  If (Recordset1.CursorType > 0) Then
    Recordset1.MoveFirst
  Else
    Recordset1.Requery
  End If

  ' set the number of rows displayed on this page
  If (Recordset1_numRows < 0 Or Recordset1_numRows > Recordset1_total) Then
    Recordset1_numRows = Recordset1_total
  End If

  ' set the first and last displayed record
  Recordset1_first = 1
  Recordset1_last = Recordset1_first + Recordset1_numRows - 1
  
  If (Recordset1_first > Recordset1_total) Then
    Recordset1_first = Recordset1_total
  End If
  If (Recordset1_last > Recordset1_total) Then
    Recordset1_last = Recordset1_total
  End If

End If
%>
<%
Dim MM_paramName 
%>
<%
' *** Move To Record and Go To Record: declare variables

Dim MM_rs
Dim MM_rsCount
Dim MM_size
Dim MM_uniqueCol
Dim MM_offset
Dim MM_atTotal
Dim MM_paramIsDefined

Dim MM_param
Dim MM_index

Set MM_rs    = Recordset1
MM_rsCount   = Recordset1_total
MM_size      = Recordset1_numRows
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
  MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%>
<%
' *** Move To Record: handle 'index' or 'offset' parameter

if (Not MM_paramIsDefined And MM_rsCount <> 0) then

  ' use index parameter if defined, otherwise use offset parameter
  MM_param = Request.QueryString("index")
  If (MM_param = "") Then
    MM_param = Request.QueryString("offset")
  End If
  If (MM_param <> "") Then
    MM_offset = Int(MM_param)
  End If

  ' if we have a record count, check if we are past the end of the recordset
  If (MM_rsCount <> -1) Then
    If (MM_offset >= MM_rsCount Or MM_offset = -1) Then  ' past end or move last
      If ((MM_rsCount Mod MM_size) > 0) Then         ' last page not a full repeat region
        MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
      Else
        MM_offset = MM_rsCount - MM_size
      End If
    End If
  End If

  ' move the cursor to the selected record
  MM_index = 0
  While ((Not MM_rs.EOF) And (MM_index < MM_offset Or MM_offset = -1))
    MM_rs.MoveNext
    MM_index = MM_index + 1
  Wend
  If (MM_rs.EOF) Then 
    MM_offset = MM_index  ' set MM_offset to the last possible record
  End If

End If
%>
<%
' *** Move To Record: if we dont know the record count, check the display range

If (MM_rsCount = -1) Then

  ' walk to the end of the display range for this page
  MM_index = MM_offset
  While (Not MM_rs.EOF And (MM_size < 0 Or MM_index < MM_offset + MM_size))
    MM_rs.MoveNext
    MM_index = MM_index + 1
  Wend

  ' if we walked off the end of the recordset, set MM_rsCount and MM_size
  If (MM_rs.EOF) Then
    MM_rsCount = MM_index
    If (MM_size < 0 Or MM_size > MM_rsCount) Then
      MM_size = MM_rsCount
    End If
  End If

  ' if we walked off the end, set the offset based on page size
  If (MM_rs.EOF And Not MM_paramIsDefined) Then
    If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
      If ((MM_rsCount Mod MM_size) > 0) Then
        MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
      Else
        MM_offset = MM_rsCount - MM_size
      End If
    End If
  End If

  ' reset the cursor to the beginning
  If (MM_rs.CursorType > 0) Then
    MM_rs.MoveFirst
  Else
    MM_rs.Requery
  End If

  ' move the cursor to the selected record
  MM_index = 0
  While (Not MM_rs.EOF And MM_index < MM_offset)
    MM_rs.MoveNext
    MM_index = MM_index + 1
  Wend
End If
%>
<%
' *** Move To Record: update recordset stats

' set the first and last displayed record
Recordset1_first = MM_offset + 1
Recordset1_last  = MM_offset + MM_size

If (MM_rsCount <> -1) Then
  If (Recordset1_first > MM_rsCount) Then
    Recordset1_first = MM_rsCount
  End If
  If (Recordset1_last > MM_rsCount) Then
    Recordset1_last = MM_rsCount
  End If
End If

' set the boolean used by hide region to check if we are on the last record
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
  MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
  MM_nextItem = "&" & MM_item & "="
  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
    MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))
  End If
Next

' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
  MM_nextItem = "&" & MM_item & "="
  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
    MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))
  End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then 
  MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "")  Then
  MM_keepURL  = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
  MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
  If (firstItem <> "") Then
    MM_joinChar = "&"
  Else
    MM_joinChar = ""
  End If
End Function
%>
<%
' *** Move To Record: set the strings for the first, last, next, and previous links

Dim MM_keepMove
Dim MM_moveParam
Dim MM_moveFirst
Dim MM_moveLast
Dim MM_moveNext
Dim MM_movePrev

Dim MM_urlStr
Dim MM_paramList
Dim MM_paramIndex
Dim MM_nextParam

MM_keepMove = MM_keepBoth
MM_moveParam = "index"

' if the page has a repeated region, remove 'offset' from the maintained parameters
If (MM_size > 1) Then
  MM_moveParam = "offset"
  If (MM_keepMove <> "") Then
    MM_paramList = Split(MM_keepMove, "&")
    MM_keepMove = ""
    For MM_paramIndex = 0 To UBound(MM_paramList)
      MM_nextParam = Left(MM_paramList(MM_paramIndex), InStr(MM_paramList(MM_paramIndex),"=") - 1)
      If (StrComp(MM_nextParam,MM_moveParam,1) <> 0) Then
        MM_keepMove = MM_keepMove & "&" & MM_paramList(MM_paramIndex)
      End If
    Next
    If (MM_keepMove <> "") Then
      MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
    End If
  End If
End If

' set the strings for the move to links
If (MM_keepMove <> "") Then 
  MM_keepMove = Server.HTMLEncode(MM_keepMove) & "&"
End If

MM_urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="

MM_moveFirst = MM_urlStr & "0"
MM_moveLast  = MM_urlStr & "-1"
MM_moveNext  = MM_urlStr & CStr(MM_offset + MM_size)
If (MM_offset - MM_size < 0) Then
  MM_movePrev = MM_urlStr & "0"
Else
  MM_movePrev = MM_urlStr & CStr(MM_offset - MM_size)
End If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
 <input name="FirstName" type="text" id="FirstName" />
 <input name="LastName" type="text" id="LastName" />
 <input name="State" type="text" id="State" />
 <input type="submit" name="Submit" value="Submit" />
</form>
<p> </p>
<p> </p>
<p> </p>
<table align="center" border="1">
 <tr>
  <td align="left" width="25%"> FirstName </td>
  <td align="left" width="25%"> LastName </td>
  <td align="left" width="25%"> State </td>
  <td align="left" width="25%"> City </td>
 </tr>
 <% 
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) 
%>
  <tr>
   <td align="left" width="25%"><a href="testsearch.asp?<%= Server.HTMLEncode(MM_keepBoth) & MM_joinChar(MM_keepBoth) & "PostPeople_ID=" & Recordset1.Fields.Item("PostPeople_ID").Value %>"><%=(Recordset1.Fields.Item("FirstName").Value)%></a> </td>
   <td align="left" width="25%"><%=(Recordset1.Fields.Item("LastName").Value)%> </td>
   <td align="left" width="25%"><%=(Recordset1.Fields.Item("State").Value)%> </td>
   <td align="left" width="25%"><%=(Recordset1.Fields.Item("City").Value)%> </td>
  </tr>
  <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>
</table>
<br>
<table border="0" width="50%" align="center">
 <tr>
  <td width="23%" align="center"><% If MM_offset <> 0 Then %>
    <a href="<%=MM_moveFirst%>">First</a>
    <% End If ' end MM_offset <> 0 %>
  </td>
  <td width="31%" align="center"><% If MM_offset <> 0 Then %>
    <a href="<%=MM_movePrev%>">Previous</a>
    <% End If ' end MM_offset <> 0 %>
  </td>
  <td width="23%" align="center"><% If Not MM_atTotal Then %>
    <a href="<%=MM_moveNext%>">Next</a>
    <% End If ' end Not MM_atTotal %>
  </td>
  <td width="23%" align="center"><% If Not MM_atTotal Then %>
    <a href="<%=MM_moveLast%>">Last</a>
    <% End If ' end Not MM_atTotal %>
  </td>
 </tr>
</table>
Records <%=(Recordset1_first)%> to <%=(Recordset1_last)%> of <%=(Recordset1_total)%>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>




rdouglass -> RE: Search Database (1/11/2008 10:53:04)

If you want all the criteria to match, use AND. If you want any criteria to match, use OR.

I think I may have botched the syntax in another place:

If Replace(trim(Recordset1__MMColParam&""), "'", "''") > "" Then
myCriteria = "(FirstName = '" & Replace(Recordset1__MMColParam, "'", "''") & "')"
End If

If Replace(trim(Recordset1__Last&""), "'", "''") > "" Then
If myCriteria > "" then
'if there is something in myCriteria put the AND clause in
myCriteria = myCriteria & " AND "
End If
myCriteria = myCriteria & "(LastName = '" & Replace(Recordset1__Last, "'", "''") & "')"
End If

If Replace(trim(Recordset1__ST&""), "'", "''") > "" Then
If myCriteria > "" then
myCriteria = myCriteria & " AND "
End If
myCriteria = myCriteria & "(State = '" & Replace(Recordset1__ST, "'", "''") & "')"
End If


See the "&" in place of those "+"? If that doesn't work, try response.write(mySQL) and see what actually is being sent as a query.

That help any?




climberman -> RE: Search Database (1/11/2008 12:15:37)

It works great except if I put in a last name and a state all of the last names come up and everyone in that state comes up even if their last name is different. If I change the or's to and's then all of the fields have to be filled in for it to work.




rdouglass -> RE: Search Database (1/13/2008 13:50:26)

quote:

If that doesn't work, try response.write(mySQL) and see what actually is being sent as a query.


Did you try that with a few scenarios? What SQL is actually being sent to the database engine?




climberman -> RE: Search Database (1/13/2008 14:25:10)

I guess I don't know how to check what is being sent to the database. You say (try response.write(mySQL)) I don't know how to try that.




rdouglass -> RE: Search Database (1/13/2008 14:30:08)

....
<body>
<%=mySQL & "<br>"
<form id="form1" name="form1" method="post" action="">
....

That should write the SQL to the page right at the top.




climberman -> RE: Search Database (1/13/2008 14:59:47)

when I do that I get this error:
Technical Information (for support personnel)

* Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/WebPages/Search.asp, line 390
=mySQL & "<br>"

Here is where I put the code:

<body>
<%=mySQL & "<br>"
<form id="form1" name="form1" method="post" action="">
<input name="FirstName" type="text" id="FirstName" />
<input name="LastName" type="text" id="LastName" />
<input name="State" type="text" id="State" />
<input type="submit" name="Submit" value="Submit" />




rdouglass -> RE: Search Database (1/13/2008 15:07:09)

quote:

<%=mySQL & "<br>"


Ooops. Sorry, I forgot to close that.[&o]

Should be:
<%=mySQL & "<br>"%>




climberman -> RE: Search Database (1/13/2008 16:14:12)

This is what I have now and nothing comes up

<body>
<%=mySQL & "<br>"%>
<form id="form1" name="form1" method="post" action="">
<input name="FirstName" type="text" id="FirstName" />
<input name="LastName" type="text" id="LastName" />
<input name="State" type="text" id="State" />
<input type="submit" name="Submit" value="Submit" />
</form>




rdouglass -> RE: Search Database (1/14/2008 13:02:34)

quote:

This is what I have now and nothing comes up


It should. Are you posting a form?




climberman -> RE: Search Database (1/14/2008 14:38:49)

The little asp thing is on the page above the text field but when I hit f12 and do a search the names come in the box but nothing above the fields.




climberman -> RE: Search Database (1/15/2008 13:59:47)

I have the ODBC data source




rdouglass -> RE: Search Database (1/15/2008 14:15:32)

So if you actually post some data in a search, nothing is written above the form?




climberman -> RE: Search Database (1/15/2008 14:25:15)

Right




rdouglass -> RE: Search Database (1/15/2008 15:45:27)

Let's try it this way; let's write it right after building it:

...
If Replace(trim(Recordset1__ST&""), "'", "''") > "" Then
If myCriteria > "" then
myCriteria = myCriteria & " AND "
End If
myCriteria = myCriteria & "(State = '" & Replace(Recordset1__ST, "'", "''") & "')"
End If

Response.write(myCriteria & "<Br>")
...

What do we get now?




climberman -> RE: Search Database (1/15/2008 17:48:31)

Ok it is working now :

(FirstName = '1') or (LastName = 'netz') or (State = 'utah')

So if I put in last name (netz) and state (utah) I get people in colorado and people that are not netz

FirstName LastName State City
Bronson Netz Utah Park City
Rocky Netz Colorado Park City
Sherry Miller Utah Price
Zair Lincoln Utah Toole
Kailas Netz Utah ST George






rdouglass -> RE: Search Database (1/16/2008 10:01:47)

quote:

(FirstName = '1') or (LastName = 'netz') or (State = 'utah')


So any ideas where that '1' coming from? Is there something in the defaults?

Anyways, you should think about the logic involved. If you want *all* of the criteria to match, use AND; if you want *any* of the criteria to match, use OR.

If you use AND and the '1' is in there, I don't think any records will be returned since probably no one has '1' for a first name.

Does any of that make sense?




climberman -> RE: Search Database (1/16/2008 10:51:59)

I don't know where that number is coming from that is my problem I suppose. If I don't put anything in a field then there should be a number there?? It must be the database I would guess.




rdouglass -> RE: Search Database (1/16/2008 11:06:51)

quote:

<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.Form("FirstName") <> "") Then
Recordset1__MMColParam = Request.Form("FirstName")
End If
%>
<%
Dim Recordset1__Last
Recordset1__Last = "2"
If (Request.Form("LastName") <> "") Then
Recordset1__Last = Request.Form("LastName")
End If
%>
<%
Dim Recordset1__ST
Recordset1__ST = "3"
If (Request.Form("State") <> "") Then
Recordset1__ST = Request.Form("State")
End If
%>


I see it now. See the defaults? They should look like this:

Recordset1__MMColParam = ""

instead of:

Recordset1__MMColParam = "1"

Do that to all 3 and we should get rid of those defaults.




climberman -> RE: Search Database (1/16/2008 11:19:02)

If I take the numbers out I get this message

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error in WHERE clause.
/WebPages/Search.asp, line 56




rdouglass -> RE: Search Database (1/16/2008 11:33:48)

quote:

/WebPages/Search.asp, line 56


What exactly is that line and can you post the 5 previous and the 5 followng lines of code?

PART 2: And does it only error when you have empty fields? Try filling all fields or does it error before you get to a form to fill out?




climberman -> RE: Search Database (1/16/2008 11:43:36)

I errors before it come up in the browser

myCriteria = myCriteria & "(State = '" & Replace(Recordset1__ST, "'", "''") & "')"
End If
Response.write(myCriteria & "<Br>")
Recordset1.Source = "SELECT * FROM PostPeople WHERE " & myCriteria
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open() This is Line 56

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<%




rdouglass -> RE: Search Database (1/16/2008 11:54:32)

I think I understand now. Let's try this, change this:

...
myCriteria = myCriteria & "(State = '" & Replace(Recordset1__ST, "'", "''") & "')"
End If
Response.write(myCriteria & "<Br>")
Recordset1.Source = "SELECT * FROM PostPeople WHERE " & myCriteria
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
...

to this:

...
myCriteria = myCriteria & "(State = '" & Replace(Recordset1__ST, "'", "''") & "')"
End If
IF myCriteria > "" THEN
myCriteria = " WHERE " & myCriteria
END IF

Response.write(myCriteria & "<Br>")
Recordset1.Source = "SELECT * FROM PostPeople" & myCriteria
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
...

That should take care of that particular issue. We were including the "WHERE" and had no criteria upon page load. However, that may load them all. If you want no records loaded upon page load, try changing that new chunk to something like this:

IF myCriteria > "" THEN
myCriteria = " WHERE " & myCriteria
ELSE
myCriteria = " WHERE LastName = 'QQQQ'"

END IF

Unless you have a record with the last name being 'QQQQ'. [;)]

That any better?




Page: [1] 2   next >   >>

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.1875