Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: RE: Error Checking with multiple variables in SQL Statement


Message #1 by "Drew, Ron" <RDrew@B...> on Mon, 13 May 2002 16:28:57 -0400
You need to check for BOF or EOF...some good error checking in this link
http://asp-help.com/database/db_errors.asp

-----Original Message-----
From: Brett Spahr [mailto:bspahr@g...]
Sent: Monday, May 13, 2002 4:23 PM
To: ASP Databases
Subject: [asp_databases] Error Checking with multiple variables in SQL
Statement



I have 2 asp pages:
  1. Search2.asp - http://www.theredzone.org/archives/search2.asp
  2. searchResults.asp -
http://www.theredzone.org/archives/searchResults.asp


Search2.asp has 2 select boxes that are both being populated from a
database.
One allows for the selection of the team and the other the date.

Everything works the way I want except for when there no record matching
the criteria - then a error is returned:

----------------------------------------------
error '80020009'

Exception occurred.

/archives/searchTeamResults.asp, line 0
----------------------------------------------



On the searchResults.asp I have 2 variables:

	criteria =3D Request.Form("Team")
	dateCriteria =3D Request.Form("headlineDate")

And then I am pulling them into the following SQL statement:

	Select * From Headlines Where Team=3D'" & criteria & "' AND
Date=3D#"
& dateCriteria & "#"


I need a way to display an error message if both variables return to
false. In other words if you select a team and date and there is no
match.


Here is the code:

<%
	Dim cnCon, rstemp, criteria, dateCriteria

	criteria =3D Request.Form("Team")
	dateCriteria =3D Request.Form("headlineDate")
	sqlState =3D "Select * From Headlines Where Team=3D'" & criteria &
"'
AND Date=3D#" & dateCriteria & "#"

	location=3Dserver.mappath.myDB.mdb")
	sourceDSN=3D"DRIVER=3D{Microsoft Access Driver (*.mdb)};"
	sourceDSN =3D sourceDSN & " DBQ=3D" & location

	Set cnCon =3D Server.CreateObject("ADODB.Connection")
	cnCon.open sourceDSN, sqlState

	If criteria =3D "" OR dateCriteria =3D "" Then
		Response.write "ERROR"
	Else
		Set rstemp =3D cnCon.Execute(sqlState)
	End If=09

%>


Anyone know of a way to do this?
Message #2 by "Brett Spahr" <bspahr@g...> on Mon, 13 May 2002 20:22:51
I have 2 asp pages: 
  1. Search2.asp - http://www.theredzone.org/archives/search2.asp 
  2. searchResults.asp - 
http://www.theredzone.org/archives/searchResults.asp


Search2.asp has 2 select boxes that are both being populated from a 
database.
One allows for the selection of the team and the other the date.

Everything works the way I want except for when there no record
matching the criteria - then a error is returned:

----------------------------------------------
error '80020009' 

Exception occurred. 

/archives/searchTeamResults.asp, line 0 
----------------------------------------------



On the searchResults.asp I have 2 variables:

	criteria = Request.Form("Team")
	dateCriteria = Request.Form("headlineDate")

And then I am pulling them into the following SQL statement:

	Select * From Headlines Where Team='" & criteria & "' AND Date=#" 
& dateCriteria & "#"


I need a way to display an error message if both variables return to false.
In other words if you select a team and date and there is no match.


Here is the code:

<%
	Dim cnCon, rstemp, criteria, dateCriteria

	criteria = Request.Form("Team")
	dateCriteria = Request.Form("headlineDate")
	sqlState = "Select * From Headlines Where Team='" & criteria & "' 
AND Date=#" & dateCriteria & "#"

	location=server.mappath.myDB.mdb")
	sourceDSN="DRIVER={Microsoft Access Driver (*.mdb)};"
	sourceDSN = sourceDSN & " DBQ=" & location

	Set cnCon = Server.CreateObject("ADODB.Connection")
	cnCon.open sourceDSN, sqlState

	If criteria = "" OR dateCriteria = "" Then
		Response.write "ERROR"
	Else
		Set rstemp = cnCon.Execute(sqlState)
	End If	

%>


Anyone know of a way to do this?

  Return to Index