Return Value of Date ans Null Function.

Hi,

I want to write a function for my code below.

to something like :

 Public Shared Function Assign_Correct_Date_Value(ByVal strData As String) As ....?

        If IsDate(strData) Then
                                        return "'" & Format(CDate(strData), "yyyy/MM/dd") & "'"
                                    Else
                                        return DBNull.Value
                                    End If

    End Function

Is it possible?

Thank you.


If IsDate(strData) Then
                                        strSQLCommand &= "'" & Format(CDate(strData), "yyyy/MM/dd") & "'"
                                    Else
                                        strSQLCommand &= DBNull.Value
                                    End If

Open in new window

LVL 1
emi_sastraAsked:
Who is Participating?
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
Wait a moment ... I don't to that way a long time ago but you can try this way

If IsDate(strData) Then
     strSQLCommand &= "'" & Format(CDate(strData), "yyyy/MM/dd") & "'"
Else
     strSQLCommand &= " NULL "
End If

Open in new window

0
 
Jorge PaulinoIT Pro/DeveloperCommented:
And that is for ?
0
 
emi_sastraAuthor Commented:
Pardon me?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Jorge PaulinoIT Pro/DeveloperCommented:
You will use that for a stored procedure or for what ?
0
 
emi_sastraAuthor Commented:
You will use that for a stored procedure or for what ?
No.

Please see below code.

Thank you.
If ERV_Global.Is_Date_Column_Field(dtRow("ColumType")) Then
                                    If IsDate(strData) Then
                                        strSQLCommand &= "'" & Format(CDate(strData), "yyyy/MM/dd") & "'"
                                    Else
                                        strSQLCommand &= DBNull.Value
                                    End If
                                End If

Open in new window

0
 
Jorge PaulinoIT Pro/DeveloperCommented:
That way I don't know if its possible ... if you use the same to build the insert values you can not include the date field but that way I don't think
0
 
emi_sastraAuthor Commented:
Ok.

  If IsDate(strData) Then
                                        strSQLCommand &= "'" & Format(CDate(strData), "yyyy/MM/dd") & "'"
                                    Else
                                        strSQLCommand &= DBNull.Value
                                    End If



Does  strSQLCommand &= DBNull.Value is a valid command for insert or update?

i.e. strSQLCommand  =  "INSERT INTO TABLEA (Date) VALUES(" & DBNull.Value

Thank you.
0
 
emi_sastraAuthor Commented:
So, below function solve the problem?

Public Shared Function Assign_Correct_Date_Value(ByVal strData As String) As String

        If IsDate(strData) Then
            Return "'" & Format(CDate(strData), "yyyy/MM/dd") & "'"
        Else
            Return " NULL "
        End If

    End Function

Thank you.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Not 100% sure but can you try ? I think is solves.
0
 
emi_sastraAuthor Commented:
Ok.

Thank you very much for your help.
0
 
emi_sastraAuthor Commented:
It works.
0
All Courses

From novice to tech pro — start learning today.