472,325 Members | 1,002 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

INSERT statement error.

I have the following to insert a new record:

<%
..

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=qqqqq;"
SQLStmt = "INSERT INTO tbl_qqqqqq (main_cat, cat_fee, fee_amount) "
SQLStmt = SQLStmt & "VALUES ('" & main_cat & "','" & cat_fee & "','" &
fee_amount & "')"
Set RS = Conn.Execute(SQLStmt)
set rs=nothing

..
%>

The "fee_amount" is a number value that has a default value associated
with that field in the Access DB.

When I submit the form WITHOUT a value in the "fee_amount" form field, I
get the following error:

"[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in
criteria expression."

That error typically means something like letters are are trying to be
inserted into a field that has a number data type.

In this case, no value has been given, when isn't the default value
being used when the INSERT statement is run?

Thanks.

Brett
ba****@sprynet.com
Oct 23 '06 #1
6 2028
"BaWork" <ba****@sprynet.comwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
>I have the following to insert a new record:

<%
.

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=qqqqq;"
SQLStmt = "INSERT INTO tbl_qqqqqq (main_cat, cat_fee, fee_amount) "
SQLStmt = SQLStmt & "VALUES ('" & main_cat & "','" & cat_fee & "','" &
fee_amount & "')"
Set RS = Conn.Execute(SQLStmt)
set rs=nothing

.
%>

The "fee_amount" is a number value that has a default value associated
with that field in the Access DB.

When I submit the form WITHOUT a value in the "fee_amount" form field, I
get the following error:

"[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria
expression."

That error typically means something like letters are are trying to be
inserted into a field that has a number data type.

In this case, no value has been given, when isn't the default value being
used when the INSERT statement is run?

Thanks.

Brett
ba****@sprynet.com
You are passing a string in your SQL for the fee_amount. What is the
datatype for the fee_amount field in your db?

--
Mike Brind
Oct 23 '06 #2
You have quotes around it. So it thinks you are inserting an empty string
(or perhaps a space).

Numeric values shouldn't have quotes around them.

And since you are generating your string dynamically, maybe you could only
include that column conditionally (e.g. when there is a value).

A

"BaWork" <ba****@sprynet.comwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
>I have the following to insert a new record:

<%
.

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=qqqqq;"
SQLStmt = "INSERT INTO tbl_qqqqqq (main_cat, cat_fee, fee_amount) "
SQLStmt = SQLStmt & "VALUES ('" & main_cat & "','" & cat_fee & "','" &
fee_amount & "')"
Set RS = Conn.Execute(SQLStmt)
set rs=nothing

.
%>

The "fee_amount" is a number value that has a default value associated
with that field in the Access DB.

When I submit the form WITHOUT a value in the "fee_amount" form field, I
get the following error:

"[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria
expression."

That error typically means something like letters are are trying to be
inserted into a field that has a number data type.

In this case, no value has been given, when isn't the default value being
used when the INSERT statement is run?

Thanks.

Brett
ba****@sprynet.com

Oct 23 '06 #3

"Mike Brind" <us********@smap.comwrote in message
news:e8**************@TK2MSFTNGP02.phx.gbl...
"BaWork" <ba****@sprynet.comwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
>>I have the following to insert a new record:

<%
.

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=qqqqq;"
SQLStmt = "INSERT INTO tbl_qqqqqq (main_cat, cat_fee, fee_amount) "
SQLStmt = SQLStmt & "VALUES ('" & main_cat & "','" & cat_fee & "','" &
fee_amount & "')"
Set RS = Conn.Execute(SQLStmt)
set rs=nothing

.
%>

The "fee_amount" is a number value that has a default value associated
with that field in the Access DB.

When I submit the form WITHOUT a value in the "fee_amount" form field, I
get the following error:

"[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria
expression."

That error typically means something like letters are are trying to be
inserted into a field that has a number data type.

In this case, no value has been given, when isn't the default value being
used when the INSERT statement is run?

Thanks.

Brett
ba****@sprynet.com

You are passing a string in your SQL for the fee_amount. What is the
datatype for the fee_amount field in your db?

--
Mike Brind
Oh, and other things you should be aware of:

1. Don't use a DSN to connect to Access. Use the OLEDB Provider.
www.connectionstrings.com
2. Don't create a recordset to insert records
http://www.aspfaq.com/show.asp?id=2191
3. Avoid messing around with delimiting values by using a saved queries
(which also helps protect against SQL injection) rather than dynamic SQL
statements.
http://groups.google.com/group/micro...d322b882a604bd

--
Mike Brind
Oct 23 '06 #4
Are you saying it should be this:

SQLStmt = SQLStmt & "VALUES ('" & main_cat & "','" & cat_fee & "',' &
fee_amount & ')"

When I do that, I get a "[Microsoft][ODBC Microsoft Access Driver]
Syntax error in INSERT INTO statement." error message.

Thanks.

Brett

Aaron Bertrand [SQL Server MVP] wrote:
You have quotes around it. So it thinks you are inserting an empty string
(or perhaps a space).

Numeric values shouldn't have quotes around them.

And since you are generating your string dynamically, maybe you could only
include that column conditionally (e.g. when there is a value).

A

"BaWork" <ba****@sprynet.comwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
>>I have the following to insert a new record:

<%
.

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=qqqqq;"
SQLStmt = "INSERT INTO tbl_qqqqqq (main_cat, cat_fee, fee_amount) "
SQLStmt = SQLStmt & "VALUES ('" & main_cat & "','" & cat_fee & "','" &
fee_amount & "')"
Set RS = Conn.Execute(SQLStmt)
set rs=nothing

.
%>

The "fee_amount" is a number value that has a default value associated
with that field in the Access DB.

When I submit the form WITHOUT a value in the "fee_amount" form field, I
get the following error:

"[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria
expression."

That error typically means something like letters are are trying to be
inserted into a field that has a number data type.

In this case, no value has been given, when isn't the default value being
used when the INSERT statement is run?

Thanks.

Brett
ba****@sprynet.com


Oct 23 '06 #5
Mike,

The data type is "number".

Thanks for the other information. I'll look into it later today.

Brett

Mike Brind wrote:
"Mike Brind" <us********@smap.comwrote in message
news:e8**************@TK2MSFTNGP02.phx.gbl...
>>"BaWork" <ba****@sprynet.comwrote in message
news:ea**************@TK2MSFTNGP04.phx.gbl...
>>>I have the following to insert a new record:

<%
.

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=qqqqq;"
SQLStmt = "INSERT INTO tbl_qqqqqq (main_cat, cat_fee, fee_amount) "
SQLStmt = SQLStmt & "VALUES ('" & main_cat & "','" & cat_fee & "','" &
fee_amount & "')"
Set RS = Conn.Execute(SQLStmt)
set rs=nothing

.
%>

The "fee_amount" is a number value that has a default value associated
with that field in the Access DB.

When I submit the form WITHOUT a value in the "fee_amount" form field, I
get the following error:

"[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria
expression."

That error typically means something like letters are are trying to be
inserted into a field that has a number data type.

In this case, no value has been given, when isn't the default value being
used when the INSERT statement is run?

Thanks.

Brett
ba****@sprynet.com

You are passing a string in your SQL for the fee_amount. What is the
datatype for the fee_amount field in your db?

--
Mike Brind


Oh, and other things you should be aware of:

1. Don't use a DSN to connect to Access. Use the OLEDB Provider.
www.connectionstrings.com
2. Don't create a recordset to insert records
http://www.aspfaq.com/show.asp?id=2191
3. Avoid messing around with delimiting values by using a saved queries
(which also helps protect against SQL injection) rather than dynamic SQL
statements.
http://groups.google.com/group/micro...d322b882a604bd

--
Mike Brind

Oct 23 '06 #6
Are you saying it should be this:
>
SQLStmt = SQLStmt & "VALUES ('" & main_cat & "','" & cat_fee & "',' &
fee_amount & ')"
No, I am saying:

SQLStmt & " SELECT '" & main_cat & "', '" & cat_fee & ", " & fee_amount

However, that dangling , will cause an error if fee_amount is empty.

A
Oct 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in...
6
by: harborboy76 | last post by:
Hi, I am trying to insert a large number of rows into a table inside a SPL. But every time, I run the SPL, the table is locked because of the...
8
by: 73blazer | last post by:
Hello, I'm looking for a way to make some of my insert templates more readable by placing comments in between the values. I cannot seem to find a...
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb -...
2
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error from the code below! Error: INSERT statement conflicted with COLUMN FOREIGN KEY...
1
by: Metal Dave | last post by:
I do not understand the error handling of SQL Server here. Any error in bulk insert seems to halt the current T-SQL statement entirely, rendering...
9
by: Jack | last post by:
Hi, I am gathering the input values to a form using Request.form method from the processing page. After all the data is captured, I am building sql...
3
by: mahajanvit | last post by:
Hi one and all I got this problem during my project. So in order to solve this I made a very small application. I am trying to insert using SP and...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password,...
1
by: Maklar60 | last post by:
I am attempting to execute an INSERT statement on my page but continually get the following error: Microsoft OLE DB Provider for ODBC Drivers...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

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.