insert NULL into access database

hi there; i have the following udate query:

Dim dtNow As DateTime = DateTime.Now
Dim strDateTime As String = dtNow.AddHours(3).ToString

If blnConfirmedByEmail = False And blnConfirmedByPhone = False Then
            'set strDateTime equal to Null here
 End If
       
        Dim strSQL As String = "UPDATE tblReservations SET " _
        & "fldReservationConfirmedByEmail=" & blnConfirmedByEmail & ", " _
        & "fldReservationConfirmedByPhone=" & blnConfirmedByPhone & ", " _
        & "fldReservationConfirmedDate='" & strDateTime & "' " _
        & "WHERE fldReservationID=" & intReservationID

as you can see, if no checkboxes are checked, then i want to update fldReservationConfirmedDate to NULL

any suggestions?

thanks all.
LVL 1
vbnewbie01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RossWilkoCommented:
Hi,

This should work

If blnConfirmedByEmail = False And blnConfirmedByPhone = False Then
            strDateTime="NULL"
 End If


        Dim strSQL As String = "UPDATE tblReservations SET " _
        & "fldReservationConfirmedByEmail=" & blnConfirmedByEmail & ", " _
        & "fldReservationConfirmedByPhone=" & blnConfirmedByPhone & ", " _
        & "fldReservationConfirmedDate='" & strDateTime & "' " _
        & "WHERE fldReservationID=" & intReservationID

although you may need to not include quotes for the null i.e
 & "fldReservationConfirmedDate=" & strDateTime _
maybe consider adding these in on strDateTime before you set strSQL

hope this helps

RW

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Éric MoreauSenior .Net ConsultantCommented:
Hi vbnewbie01,

but NULL cannot be inserted between '

If blnConfirmedByEmail = False And blnConfirmedByPhone = False Then
            strDateTime="NULL"
else
            strDateTime="'" & strDateTime & "'"
 End If

        Dim strSQL As String = "UPDATE tblReservations SET " _
        & "fldReservationConfirmedByEmail=" & blnConfirmedByEmail & ", " _
        & "fldReservationConfirmedByPhone=" & blnConfirmedByPhone & ", " _
        & "fldReservationConfirmedDate=" & strDateTime & " " _
        & "WHERE fldReservationID=" & intReservationID

Cheers!
vbnewbie01Author Commented:
hi, guys; thank you both very much for your response.  i had been trying to set strDateTime = Null (without the quotes) and couldn't figure out why this wasn't working.  I then added the quotes and it still didn't work.

turns out, as you both suggested, i needed to remove the single quotes from around strDateTime in my query.

anyway, i have split the points to accomodate emoreau's slightly more detailed solution.

thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.