Link to home
Create AccountLog in
Avatar of donaldcroswell
donaldcroswell

asked on

myCommand.Parameters.Add with a NULL value in a smalldatetime field

Hello Experts,

I'm having dramas inserting null a null value into my database smalldatetime field.

I check the fields first on the form
        Dim strDate As String
        If Trim(myDay) = "" Or Trim(myMonth) = "" Or Trim(myYear) = "" Then
            strDate = System.DBNull.Value.ToString
        Else
myCommand.Parameters.Add("@FamDOB", Data.SqlDbType.SmallDateTime).Value

For some reason if there is a value my code works, but the System.DBNull.Value.ToString doesn't work with or without quotes added.

Any help?

Cheers
Don
ASKER CERTIFIED SOLUTION
Avatar of Fareed Ali Khan
Fareed Ali Khan
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of donaldcroswell
donaldcroswell

ASKER

Thanks Fareed,

It is actually in a function that is across the entire site. It drops dates into SQL and it is used for parameters.

Is there a way I can get it to do both with out changing all of the places it is used?

Cheers
Don
just find and replace