Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / July 2005



Tip: Looking for answers? Try searching our database.

Changing a value to Null during update

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RDufour - 27 Jul 2005 19:39 GMT
   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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.