473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Checkbox & Queries

I am working on a youth rights website, and while working on the membership application, I receive an datatype mismatch error.

I have pinpointed the error to be related to checkbox values.

All form variables are passed to the next page which then stores the forms values as session variables.

In the database, each of the database fields are set to Yes/No datatypes. Check forms checkbox saves its variable in the session as 'on' for true.

Here is the error I receive:
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
And here is just one of my queries, as a three have the same issues:
Support = oConn.Execute("INSERT INTO membership_support (AccountNumber, [money], Other) VALUES('" &Session.SessionID& "', '" &money& "', '" &OtherHelp& "')")
Any help would be appreciated.
Mar 20 '08 #1
6 1959
DrBunchman
979 Expert 512MB
Hi there,

In order to find out the cause of a sql error a simple method is to print your sql string to the screen with a response.write (comment out the actual update statement) then try and run it in query analyser. That way you can see whether your variables are being passed to your sql correctly.

Can you do the above and print your sql here. Also check what values your datatypes will accept. I've never heard of a Yes/No datatype but presume it is a Boolean type which will only accept True or False.

Dr B
Mar 20 '08 #2
jeffstl
432 Expert 256MB
I am working on a youth rights website, and while working on the membership application, I receive an datatype mismatch error.

I have pinpointed the error to be related to checkbox values.

All form variables are passed to the next page which then stores the forms values as session variables.

In the database, each of the database fields are set to Yes/No datatypes. Check forms checkbox saves its variable in the session as 'on' for true.

Here is the error I receive:
And here is just one of my queries, as a three have the same issues:
Any help would be appreciated.
Access Yes\No fields never seem to work right in my experience.

However, you can try this in the SQL

Whichever field is your checkbox field you need to treat it like a number rather then a string. so " & Money & " instead of '" & Money "'

This is because the Yes\No datafield interprets 0 and -1 as the yes and no.

If this doesnt work I would change the yes\no datafield to a Text field and simply store the actualy letter Y or N in that field based on what the checkbox value is in code.

If chkBox.Value = -1 then
MyValue = "Y"
end if


Then you can treat it like a string instead of a number and its easier to deal with.
Mar 20 '08 #3
Okay, let me try this again (browser crashed mid post)


What I have done to get the error is the following

joinchapter.asp
<form method=post action=joinsubmit.asp>
<input type=checkbox name=money> Donate
<input type=submit>

joinsubmit.asp
Session("money") = Request.Form("money")
Details = oConn.Execute("INSERT INTO membership_support (AccountNumber, [money]) VALUES('" &Session.SessionID& "', '" &Session("money")& "')")

When I then do a Response.Write to the screen on Session("money") I get "on" as the result if the checkbox was checked.


The Access database has the field datatype for money set to true/false (boolean). However, in Access you can also select its format from Yes/No (default), True/False and On/Off (I have tried them all; no joy).

I have tried changing "on" to "true", but still receive the same error. I have used checkboxes before in a similar manner, and have not had this issue.

I have even tried to insert directly, by Request.Form("money") and by declaring it as a variable in the querystring. No success!
Mar 20 '08 #4
jeffstl
432 Expert 256MB
Okay, let me try this again (browser crashed mid post)


What I have done to get the error is the following

joinchapter.asp
<form method=post action=joinsubmit.asp>
<input type=checkbox name=money> Donate
<input type=submit>

joinsubmit.asp
Session("money") = Request.Form("money")
Details = oConn.Execute("INSERT INTO membership_support (AccountNumber, [money]) VALUES('" &Session.SessionID& "', '" &Session("money")& "')")

When I then do a Response.Write to the screen on Session("money") I get "on" as the result if the checkbox was checked.


The Access database has the field datatype for money set to true/false (boolean). However, in Access you can also select its format from Yes/No (default), True/False and On/Off (I have tried them all; no joy).

I have tried changing "on" to "true", but still receive the same error. I have used checkboxes before in a similar manner, and have not had this issue.

I have even tried to insert directly, by Request.Form("money") and by declaring it as a variable in the querystring. No success!
As I said before the Yes\No data type in access doesnt work across platforms very well...its looking for a Microsoft defined boolean data type..... It may in fact be a data type specifically meant for access forms only (rather then web or vb forms).

Either way though doesn't matter ...your error is directly related to the SQL string not being properly formatted for the corresponding data type in your table. I pretty much gaurantee that.

I would suggest changing the data type to Text in the table, and storing your value as a "Y" or an "N" instead .....depending on what is the value of the check using an IF statement.

This is the quickest solution to your problem.

Expand|Select|Wrap|Line Numbers
  1. If Request.Form("money") = 1 then
  2.      Session("Money") = "Y"
  3. End If
  4.  
  5. 'OR if your really getting on and off which i havent seen before (shoudl be 0 or 1)
  6. If Request.Form("money") = "on" then
  7.      Session("Money") = "Y"
  8. End If
  9.  

If you simply HAVE to get the yes\no data type to work then you will need to try both the single quote and NO single quote around the SQL variable Money......... to see if it can be passed as a number or a string or what it will accept.

If it accepts niether and you still get the same error then it pretty much proves that the Access Yes\No data type does not work outside of Access originated SQL ........and I would change it to Text, then format your "Money" variable to be a "Y" or an "N" before you build your SQL string.
Mar 20 '08 #5
Okay thanks, I think I have it figured out. I don't know what I have changed over the past few months in my programming technique, but apparently something has changed. I used to use checkbox values with Access. I know I used to use the add.new function, now I use "Insert into". Maybe that is why I now get the error.

Anyways, what I did was change the true/false datatype to a byte formatted number type, this was I can stick with 1 or 0 in the advent that I upgrade to sql in the future.
Mar 21 '08 #6
jhardman
3,406 Expert 2GB
Okay thanks, I think I have it figured out. I don't know what I have changed over the past few months in my programming technique, but apparently something has changed. I used to use checkbox values with Access. I know I used to use the add.new function, now I use "Insert into". Maybe that is why I now get the error.

Anyways, what I did was change the true/false datatype to a byte formatted number type, this was I can stick with 1 or 0 in the advent that I upgrade to sql in the future.
There's actually an article on this phenomenon in the ASP How-to section including solutions. I believe the solution that markrawlingson (the author, one of our forum experts) suggests is to add a value attribute to the checkbox, if you are using Access, then you would get the following
Expand|Select|Wrap|Line Numbers
  1. value="True"
. This changes the sent data from "on" to "True" which should be insertable in the access db.

Jared
Mar 21 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: thejackofall | last post by:
Hi. I have a checkbox column in my datagrid like this: <Columns> <asp:TemplateColumn HeaderText=" "> <ItemTemplate> <asp:CheckBox ID='Selection' runat="server"></asp:CheckBox> <asp:Label...
3
by: elyob | last post by:
Okay, I'm about to add some checkboxes to a form, and then store the data in a column on a MySQL database. Just wanted to know best practice, at the moment I'm writing and thinking .. God that's...
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
1
by: rn5a | last post by:
A ASPX page has a DataList control with a few Labels. This page also has a CheckBox which resides OUTSIDE the DataList. By default, this CheckBox is checked. If the CheckBox is checked, then the...
4
by: arizal | last post by:
Hi , I am trying to figure out why my PHP code to delete multiple value by selecting the checkbox is not working. My php code is listed as below <?php $sql = "Select * from list;";...
8
by: Sid | last post by:
I hope someone could help me with this. I am trying to setup a criteria to decide when to allow/not allow user to click on the check box. logically it looks simple but I am not able to...
1
by: inamul | last post by:
I want to select CheckBox based on data retrieved from mysql database table. Could anyone show me the simple way of doing it. Data store in table under colum "sectionOfInterest" is shown below...
1
by: inamul | last post by:
I want to select CheckBox based on data retrieved from mysql database table. Could anyone show me the simple way of doing it. Data store in table under colum "sectionOfInterest" is shown below...
7
by: avraamG13 | last post by:
Hello, I'm having a code that shows in a list checkbox and next the row name i have on my database I want to select a checkbox and when i press display to show me tha information of the specific...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.