razzmusit
asked on
Data type mismatch in criteria expression, when using INSERT INTO
When using an INSTER INTO statement i get a "Data type mismatch in criteria expression".
I am using VBscript and an Access database.
The field I am trying to write to is a number-field.
The code:
<%
if(Request("1Lang_ID") <> "") then addProduct__strLanguage = Request("1Lang_ID")
%>
<%
set addProduct = Server.CreateObject("ADODB .Command")
addProduct.ActiveConnectio n = MM_Seed2data_STRING
addProduct.CommandText = "INSERT INTO t_text (text_Language) VALUES ('" + Replace(addProduct__strLan guage, "'", "''") + "') "
addProduct.CommandType = 1
addProduct.CommandTimeout = 0
addProduct.Prepared = true
addProduct.Execute()
%>
what am i doing wrong ?
I am using VBscript and an Access database.
The field I am trying to write to is a number-field.
The code:
<%
if(Request("1Lang_ID") <> "") then addProduct__strLanguage = Request("1Lang_ID")
%>
<%
set addProduct = Server.CreateObject("ADODB
addProduct.ActiveConnectio
addProduct.CommandText = "INSERT INTO t_text (text_Language) VALUES ('" + Replace(addProduct__strLan
addProduct.CommandType = 1
addProduct.CommandTimeout = 0
addProduct.Prepared = true
addProduct.Execute()
%>
what am i doing wrong ?
Hi razzmusit,
Try this:
"INSERT INTO t_text (text_Language) VALUES (" & Val(Replace(addProduct__st rLanguage, "'", "''")) & ") "
Cheers!
Try this:
"INSERT INTO t_text (text_Language) VALUES (" & Val(Replace(addProduct__st
Cheers!
Dave,
>> numberic
I like that word :o)
>> numberic
I like that word :o)
ASKER
>>Flavo
You solution generated the same error > "Data type mismatch in criteria expression"
>>will_scarlet7
Now I get " Type mismatch: 'Val' "
Perhabs I should convert it to a "numberic" value - which must be a third format I havent yet discovered - hehe ;)
Typo :-(
"INSERT INTO t_text (text_Language) VALUES (" + cdbl(addProduct__strLangua ge) + ");"
Dave
"INSERT INTO t_text (text_Language) VALUES (" + cdbl(addProduct__strLangua
Dave
ASKER
This is getting weirder and weirder - now I get the error:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "INSERT INTO t_text ("]'
/seed2/add_prod_test.asp, line 41
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "INSERT INTO t_text ("]'
/seed2/add_prod_test.asp, line 41
> addProduct.CommandTimeout = 0
I think this should be a little higher, maybe? Never tried setting it to such a low value.
"Indicates how long to wait while executing a command before terminating the attempt and generating an error."
Maybe this is why there is an error???
Dave
I think this should be a little higher, maybe? Never tried setting it to such a low value.
"Indicates how long to wait while executing a command before terminating the attempt and generating an error."
Maybe this is why there is an error???
Dave
ASKER
Nope - that didn´t do the trick..
> addProduct.CommandTimeout = 0
I believe this means there is NO timeout, therefore it will keep trying to run until it returns a result or errors
What about i.e. a single double quote rather than a double single quote ;-)
VALUES ('" + Replace(addProduct__strLan guage, "'", """") + "') "
I believe this means there is NO timeout, therefore it will keep trying to run until it returns a result or errors
What about i.e. a single double quote rather than a double single quote ;-)
VALUES ('" + Replace(addProduct__strLan
Are we 100% all table and field names are correct?
If all else fails, try wraping them in []
"INSERT INTO [t_text] ([text_Language]) VALUES (" + cdbl(addProduct__strLangua ge) + ");"
If all else fails, try wraping them in []
"INSERT INTO [t_text] ([text_Language]) VALUES (" + cdbl(addProduct__strLangua
>> The field I am trying to write to is a number-field.
Oh! Do you not need to validate the input to check it is numeric (you can use IsNumeric)? Your replace implies that it is unlikely yo be. How about since you seem to expect single quotes in there):
"INSERT INTO [t_text] ([text_Language]) VALUES (" + cdbl(Replace(addProduct__s trLanguage , "'", "")) + ")"
Oh! Do you not need to validate the input to check it is numeric (you can use IsNumeric)? Your replace implies that it is unlikely yo be. How about since you seem to expect single quotes in there):
"INSERT INTO [t_text] ([text_Language]) VALUES (" + cdbl(Replace(addProduct__s
ASKER
Returns the error:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'cdbl'
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'cdbl'
Well Im guessing that addProduct__strLanguage isn't numeric
As pootle_flump eluded to earlier try this
If not IsNumeric(addProduct__strL anguage) Then
response.write("oh ohhh")
exit sub
else
addProduct.CommandText = "INSERT INTO [t_text] ([text_Language]) VALUES (" + addProduct__strLanguage + ");"
end if
As pootle_flump eluded to earlier try this
If not IsNumeric(addProduct__strL
response.write("oh ohhh")
exit sub
else
addProduct.CommandText = "INSERT INTO [t_text] ([text_Language]) VALUES (" + addProduct__strLanguage + ");"
end if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah - "time of running the code" was the key - off course!!!!
"addProduct__strLanguage" had no value at the time of running the code.
thanxalot
"addProduct__strLanguage" had no value at the time of running the code.
thanxalot
Lol - you need to account for that in your input validation. Check out Dave (flavo's post) - IsNumeric will identify nulls too
When refering to a numeric field, you don't need to wrap the value in ' (I'm guessing you mean text_Language is numberic data type)
Try this
addProduct.CommandText = "INSERT INTO t_text (text_Language) VALUES (" + addProduct__strLanguage+ ") "
Dave :-)