Data type mismatch in criteria (Full Version)

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



Message


slbergh -> Data type mismatch in criteria (8/15/2006 23:33:23)

I'm pulling my hair out trying to figure out why I keep getting a data type mismatch error on this page. What I'm doing is a simple registration form which posts to a custom confirmation page. In a second DRW on this page, I'm trying to pull and display the UserID and Timestamp from the record I just inserted with the form. As long as I don't try to add any type of WHERE clause, it works...sort of. It displays all of the records, rather than just the current one.

Maybe my mistake will jump out at someone else, because I certainly can't find it!




<h2>REGISTRATION COMPLETE!</h2>

<!--#include file="_fpclass/fpdblib.inc"-->
<%
fp_sQry="SELECT * FROM Registration"
fp_sDefault=""
fp_sNoRecords="No records returned."
fp_sDataConn="vr"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=False
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_sColTypes="&UserID=3&EmailAddress=202&
TakenOnlineCourses=11&TakenSafetyCourses=11&
ComputerComfort=3&WorkSetting=3&WorkSettingOther=202&
AgreeToParticipate=11&HaveReadConsentDoc=11&
Remote_computer_name=202&User_name=202&
Browser_type=202&Timestamp=135&"
fp_iDisplayCols=13
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>
<!--#include file="_fpclass/fpdbrgn1.inc"-->
<!--#include file="_fpclass/fpdbrgn2.inc"-->
<p>Thank you for registering as a participant. Please print this page for your
records. You will need your participant number to take the training.</p>
<div id="confirmation"><!--#include file="_fpclass/fpdblib.inc"-->

<%
fp_sQry="SELECT * FROM Registration WHERE UserID ='" & Session("#UserID#") & "'"
fp_sDefault=""
fp_sNoRecords="No records returned."
fp_sDataConn="vr"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=False
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_sColTypes="&UserID=3&EmailAddress=202&Timestamp=135&"
fp_iDisplayCols=13
fp_fCustomQuery=True
BOTID=1
fp_iRegion=BOTID
%>
<!--#include file="_fpclass/fpdbrgn1.inc"-->
<%=FP_FieldVal(fp_rs,"UserID")%></p>
<p><%=FP_FieldVal(fp_rs,"EmailAddress")%></p>
<p><%=FP_FieldVal(fp_rs,"Timestamp")%><!--#include file="_fpclass/fpdbrgn2.inc"-->
</div>




BeTheBall -> RE: Data type mismatch in criteria (8/15/2006 23:54:46)

UserID is probably numeric. Change your SQL to:

fp_sQry="SELECT * FROM Registration WHERE UserID =" & Session("UserID")

Note: Not sure what the # is doing in there.




slbergh -> RE: Data type mismatch in criteria (8/16/2006 12:25:02)

That statement gave me the following error:

Error Type:
Microsoft VBScript compilation (0x800A0409)
Unterminated string constant
/VRProject/confirm.asp, line 27, column 72
fp_sQry="SELECT * FROM Registration WHERE UserID =" & Session("UserID")"

Erg! This is so frustrating! I know the answer is sitting right in front of my face!! Oh, and I had the # in there because I saw several postings that said you needed them with numbers.




BeTheBall -> RE: Data type mismatch in criteria (8/16/2006 12:26:43)

Lose the last double quote.

fp_sQry="SELECT * FROM Registration WHERE UserID =" & Session("UserID")




slbergh -> RE: Data type mismatch in criteria (8/16/2006 12:45:41)

Database Results Error
Description: Syntax error (missing operator) in query expression 'UserID ='.
Number: -2147217900 (0x80040E14)
Source: Microsoft JET Database Engine

I stared at this one quite a bit last night, too!




BeTheBall -> RE: Data type mismatch in criteria (8/16/2006 12:50:04)

Ok, that makes me think your Session variable is empty. Can you response.write it somewhere on the page?

<%=Session("UserID")%>




slbergh -> RE: Data type mismatch in criteria (8/17/2006 0:30:38)

Nope.

I even tried following a Spooky tutorial. All I can do is display all records. As soon as I put any kind of qualifier in, I get the same error again.

Here's the code from the submitting form:

<%

On Error Resume Next
Session("FP_OldCodePage") = Session.CodePage
Session("FP_OldLCID") = Session.LCID
Session.CodePage = 1252
Err.Clear

strErrorUrl = ""

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
If Request.Form("VTI-GROUP") = "0" Then
Err.Clear

Set fp_conn = Server.CreateObject("ADODB.Connection")
FP_DumpError strErrorUrl, "Cannot create connection"

Set fp_rs = Server.CreateObject("ADODB.Recordset")
FP_DumpError strErrorUrl, "Cannot create record set"

fp_conn.Open Application("new_page_12_ConnectionString")
FP_DumpError strErrorUrl, "Cannot open database"

fp_rs.Open "Results", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable
FP_DumpError strErrorUrl, "Cannot open record set"

fp_rs.AddNew
FP_DumpError strErrorUrl, "Cannot add new record set to the database"
Dim arFormFields0(1)
Dim arFormDBFields0(1)
Dim arFormValues0(1)

arFormFields0(0) = "EmailAddress"
arFormDBFields0(0) = "EmailAddress"
arFormValues0(0) = Request("EmailAddress")
arFormFields0(1) = "TakenOnlineCourses"
arFormDBFields0(1) = "TakenOnlineCourses"
arFormValues0(1) = Request("TakenOnlineCourses")
arFormFields0(2) = "TakenSafetyCourses"
arFormDBFields0(2) = "TakenSafetyCourses"
arFormValues0(2) = Request("TakenSafetyCourses")
arFormFields0(3) = "ComputerComfort"
arFormDBFields0(3) = "ComputerComfort"
arFormValues0(3) = Request("ComputerComfort")
arFormFields0(4) = "WorkSetting"
arFormDBFields0(4) = "WorkSetting"
arFormValues0(4) = Request("WorkSetting")
arFormFields0(5) = "WorkSettingOther"
arFormDBFields0(5) = "WorkSettingOther"
arFormValues0(5) = Request("WorkSettingOther")
arFormFields0(6) = "AgreeToParticipate"
arFormDBFields0(6) = "AgreeToParticipate"
arFormValues0(6) = Request("AgreeToParticipate")
arFormFields0(7) = "HaveReadConsentDoc"
arFormDBFields0(7) = "HaveReadConsentDoc"
arFormValues0(7) = Request("HaveReadConsentDoc")

FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0

If Request.ServerVariables("REMOTE_HOST") <> "" Then
FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_HOST"), "Remote_computer_name"
End If
If Request.ServerVariables("HTTP_USER_AGENT") <> "" Then
FP_SaveFieldToDB fp_rs, Request.ServerVariables("HTTP_USER_AGENT"), "Browser_type"
End If
FP_SaveFieldToDB fp_rs, Now, "Timestamp"
If Request.ServerVariables("REMOTE_USER") <> "" Then
FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_USER"), "User_name"
End If

fp_rs.Update
ID = fp_rs(0)
FP_DumpError strErrorUrl, "Cannot update the database"

fp_rs.Close
fp_conn.Close

FP_FormConfirmation "text/html; charset=windows-1252",_
"Form Confirmation",_
"Record ID "&ID&" - Thank you for submitting the following information:",_
"confirm.asp?ID="& ID,_
"Return to the form."

End If
End If

Session.CodePage = Session("FP_OldCodePage")
Session.LCID = Session("FP_OldLCID")

%>


<!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=utf-8" />
<title>Implementation of Virtual Reality</title>
<link rel="stylesheet" type="text/css" href="vrstyle.css" />
</head>

<body>

<div id="layout">
	<div id="content">
		<h1>Implementation of Virtual Reality Environments in Online Health and 
		Safety Training<br>
		Project Website</h1>
		<p class="center"><span class="name">Investigator: Sherry Berghefer, Master's 
		Candidate</span></p>
		<p> </p>
		<p class="bold">Please complete the following form in order to register 
		as a participant.</p>
		<form method="POST" action="confirm.asp" name="StudyRegistration">

		<input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--#include file="_fpclass/fpdbform.inc"-->
			<p>Email address (for communication purposes only):
			<input name="EmailAddress" type="text" maxlength="20" 
   tabindex="1" size="20" /><br />
			<br />
			Have you ever taken an online course in the past?  
			<input name="TakenOnlineCourses" type="radio" value="1" 
   tabindex="2" title="Yes" /> Yes  <input name="TakenOnlineCourses" 
   type="radio" tabindex="2" title="No" value="0" />No<br />
			<br />
			If yes, have you ever taken online safety training courses? 
			<input name="TakenSafetyCourses" type="radio" value="1" 
   tabindex="3" title="Yes" /> Yes  <input name="TakenSafetyCourses" 
   type="radio" tabindex="3" title="No" value="0" />No<br />
			<br />
			Please rate your comfort level in using a computer to complete tasks?  
			<select name="ComputerComfort" tabindex="4" size="1">
			<option value="99">- Select your comfort level -</option>
			<option value="5">Very Comfortable</option>
			<option value="4">Somewhat Comfortable</option>
			<option value="3">Neutral</option>
			<option value="2">Somewhat Uncomfortable</option>
			<option value="1">Very Uncomfortable</option>
			</select><br />
			<br />
			What is your usual work setting?  
			<select name="WorkSetting" 
   tabindex="5" size="1">
			<option value="99">- Select your usual work setting -</option>
			<option value="1">Laboratory</option>
			<option value="2">Office</option>
			<option value="3">Other</option>
			</select><br />
			<br />
			If other, please specify: 
			<input name="WorkSettingOther" type="text" 
   style="width: 253px" tabindex="6" size="20" /><br />
			<br />
			<input name="AgreeToParticipate" type="checkbox" value="1" 
   tabindex="7" />  I understand that by agreeing to participate in this study, 
			I am consenting to receive emails directly related to the study from 
			Sherry Berghefer and/or the Iowa State University 
			Office of Research Assurances. I also understand that my information 
			will be kept confidential and that those involved in the study will 
			not use my email address for any other purpose. <br />
			<br />
			<input name="HaveReadConsentDoc" type="checkbox" value="1" 
   tabindex="8" />  I have read the Informed Consent document and have had 
			adequate opportunity to ask questions. I understand that my participation 
			is voluntary. I also understand that I may decide to no longer participate 
			at any time, without penalty. By checking this box, I am volunteering 
			to participate in this study. <br />
			<br />
			<input name="Submit" type="submit" value="Submit Registration" 
   tabindex="9" /></p>
		</form>
	</div>
</div>

</body>

</html>


and the confirmation page:

<!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=utf-8" />
<title>Implementation of Virtual Reality</title>
<link rel="stylesheet" type="text/css" href="vrstyle.css" />
</head>

<body>



<div id="layout">
<div id="content">
<h1>Implementation 
of Virtual Reality Environments in Online Health and Safety Training<br>
Project Website</h1>
<p class="center"><span class="name">Investigator: Sherry Berghefer, Master's Candidate</span></p>
<h2>REGISTRATION COMPLETE!</h2>

<p>Thank you for registering as a participant. Please print this page for your 
records. You will need your participant number to take the training.</p>
<div id="confirmation">

<!--#include file="_fpclass/fpdblib.inc"-->

<%
fp_sQry="SELECT * FROM Registration"
fp_sDefault=""
fp_sNoRecords="No records returned."
fp_sDataConn="vr"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=False
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_sColTypes="&ID=3&EmailAddress=202&TakenOnlineCourses=11&TakenSafetyCourses=11&ComputerComfort=3&WorkSetting=3&WorkSettingOther=202&AgreeToParticipate=11&HaveReadConsentDoc=11&Remote_computer_name=202&User_name=202&Browser_type=202&Timestamp=135&VTI-GROUP=202&"
fp_iDisplayCols=1
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>
<!--#include file="_fpclass/fpdbrgn1.inc"-->
<p>You 
registered on <%=FP_FieldVal(fp_rs,"Timestamp")%>. Your participant 
number is <%=Request.Querystring("ID")%>.</p>
<!--#include file="_fpclass/fpdbrgn2.inc"-->
</p>
	
</div><p>
<a href="vr/index.html">Take the training --></a></p></div></div>
</body>

</html>




BeTheBall -> RE: Data type mismatch in criteria (8/17/2006 9:51:27)

It's not a session variable. Try this SQL:

fp_sQry="SELECT * FROM Registration WHERE UserID =::ID::"




slbergh -> RE: Data type mismatch in criteria (8/17/2006 10:19:01)

Database Results Error
Description: Syntax error (missing operator) in query expression 'UserID ='.
Number: -2147217900 (0x80040E14)
Source: Microsoft JET Database Engine

One or more form fields were empty. You should provide default values for all form fields that are used in the query.




Spooky -> RE: Data type mismatch in criteria (8/17/2006 10:35:05)

Use the session as Duane mentioned, but change the processing page like so :
fp_rs.Close
fp_conn.Close

Session("ID") = ID 





slbergh -> RE: Data type mismatch in criteria (8/17/2006 15:50:55)

Database Results Error
Description: Syntax error (missing operator) in query expression 'ID ='.
Number: -2147217900 (0x80040E14)
Source: Microsoft JET Database Engine

One or more form fields were empty. You should provide default values for all form fields that are used in the query.

------------
Maybe I should find a different way to achieve what I'm trying to do!!




BeTheBall -> RE: Data type mismatch in criteria (8/17/2006 16:53:33)

I think I see the problem. Your code is NOT submitting to a custom confirmation page. If it were, you would see a redirect statement in the red code at the top of the page. I suggest you begin anew and when you choose the "Send to Database" option in the form properties, make sure you also set it to have a custom confirmation page. In other words, there needs to be two pages. The one your form is on and the confirmation page. You then use Spooky's tutorial to carry the record ID from page 1 to page 2 and on page 2 you select the record details that correspond the the ID.




slbergh -> RE: Data type mismatch in criteria (8/17/2006 17:07:20)

What's weird is that I AM using two pages: register.asp and confirm.asp! I'll try redoing them.




BeTheBall -> RE: Data type mismatch in criteria (8/17/2006 19:08:20)

Let me ask you this. When you submit a new record, is it actually making it to the database? Try it and let me know.




slbergh -> RE: Data type mismatch in criteria (8/18/2006 9:41:08)

Yep, it's writing to the database.




BeTheBall -> RE: Data type mismatch in criteria (8/18/2006 9:47:51)

And the two items of code here:

http://www.frontpagewebmaster.com/fb.asp?m=337669

are the fully code for each of the two pages in question? Let me tell you why I suspected nothing was posting to the database. In the code for the form, you have this:

<form method="POST" action="confirm.asp" name="StudyRegistration">

Since the action is set to confirm.asp, that would make the code bypass all the red code at the top of the page that handles the record insertion. The page should post to itself.




slbergh -> RE: Data type mismatch in criteria (8/18/2006 10:09:00)

About the same time you posted the last one, I wound up with working code. Of course, I "cheated" a bit to get it...my husband was tired of seeing me pull my hair out over it, so he asked one of his web programmers to write a working page for me. His is pure asp, rather than FP asp and it's only one page rather than two, but it works! I can post it if you'd like to see how he handled it.

I appreciate all your help, and Spooky's too. Now, I can get past the easy part of project and move on to the hard stuff...making a hotspot in a flash movie display a database record in a div. (Am I a glutton for punishment or what?!?!?) With luck, I'll just barely get the project done, tested and defended in time to graduate Dec. 8!




BeTheBall -> RE: Data type mismatch in criteria (8/18/2006 10:30:54)

Good luck. Glad you worked it out. Just another example of how wonderful us husbands can be. [:)]




slbergh -> RE: Data type mismatch in criteria (8/18/2006 11:48:30)

Yep, you all are good for something after all! [:D]




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.125