Trying to put a NULL value in a Sql database field. The following code
snippet does not work
Dim Sql As String
Dim SQLDB As ADODB.Connection
Set SQLDB = New ADODB.Connection
SQLDB.CursorLocation = adUseClient
SQLDB.Open "PROVIDER=SQLOLEDB;User ID=sa;Password=PWD;Data
Source=MyComp;Initial Catalog=Test;"
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
Sql = "select * from Mytable where Id = 2"
Rs.Open Sql, SQLDB, adOpenKeyset, adLockOptimistic
If Not Rs.EOF And Not Rs.BOF Then
'******* Works fine up to here, the record is found, but the NULL
value does not get saved to field. it is integer type and allows nulls in DB
but I can't put in value 0 because its A foreign key field and there is no
parent record with a Primary key value of 0
Rs("MyNullableField") = vbNull
Rs.Update
End If
can anyone tell me syntax for changingf rs field value to NULL
Thanks for any help.
RD
RDufour - 27 Jul 2005 19:45 GMT
Additionally I just realized by running the test again that it does change
the value of the field on update to 1.
Help realy appreciated on this one, weird
RD
> Trying to put a NULL value in a Sql database field. The following code
> snippet does not work
[quoted text clipped - 23 lines]
>
> RD
Al Reid - 28 Jul 2005 12:50 GMT
> Trying to put a NULL value in a Sql database field. The following code
> snippet does not work
[quoted text clipped - 23 lines]
>
> RD
Try using NULL instead of vbNull. vbNull is a constant with a value of 1 whereas NULL is null.
--
Al Reid