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
.NET ProgrammingDatabasesASP.NET

Avatar of undefined
Last Comment
Fareed Ali Khan

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Fareed Ali Khan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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
Fareed Ali Khan

just find and replace
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes