Skip to main content
Inspiring
October 23, 2006
Question

INSERT code error...(ASP)

  • October 23, 2006
  • 1 reply
  • 221 views
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
bawork@sprynet.com
This topic has been closed for replies.

1 reply

Inspiring
October 23, 2006
Because you have quotes around your values. The final query will look like
INSERT INTO qqqqqq(a,b,c,d)
VALUES('a','b','c','d')

If no value is given, you'll have '' inserted. An empty string is not a
NULL. Even then, you might have to use the keyword DEFAULT to avoid getting
'column c does not allow NULLs; insert failed' message.


"Ba Work" <bawork@sprynet.com> wrote in message
news:ehio8p$38j$1@forums.macromedia.com...
>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
> bawork@sprynet.com