Click to See Complete Forum and Search --> : INSERT nullstring INTO


Dr_Michael
January 27th, 2005, 06:33 AM
I execute an SQL statement "INSERT INTO ... VALUES ...", but if one of the values is null string ("") then SQL fails. What can I do for this?
I am using VB6, ADO 2.7 and Access 2000.

Dr_Michael
January 27th, 2005, 07:21 AM
Resolved: I had a field with name DATE which conflicts with the DATE function of VB. I changed its name to BILLDATE and now it works no matter if there is null string or not.

erickwidya
January 28th, 2005, 12:47 AM
Date is also a Reserved word in Access..u may want to consider change the field name or use [] bracket

Davey
January 28th, 2005, 02:44 AM
Is there any reason you are inserting an empty string "" rather than NULL?

Krzemo
January 28th, 2005, 06:02 AM
but if one of the values is null string ("") then SQL fails. What can I do for this?
Generaly speaking this is a very bad idea to concatenate strings for executing SQL in ADO.I'm almost sure that U've done something like that: strSQL="INSERT INTO .... VALUES('" & strVar1 & "')".
It leads to "SQL injection" problem (and also to a problem that U discover ;) ).
Proper (and safe) way to do it is to execute parametrized SQL in ADO.

Best regards,
Krzemo.