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.
Printable View
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.
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.
Date is also a Reserved word in Access..u may want to consider change the field name or use [] bracket
Is there any reason you are inserting an empty string "" rather than NULL?
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 & "')".Quote:
but if one of the values is null string ("") then SQL fails. What can I do for this?
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.