Solved

Return Value of Date ans Null Function.

Posted on 2009-04-07
11
160 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:emi_sastra
  • 6
  • 5
11 Comments
 
LVL 48

Expert Comment

by:jpaulino
Comment Utility
And that is for ?
0
 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
Pardon me?
0
 
LVL 48

Expert Comment

by:jpaulino
Comment Utility
You will use that for a stored procedure or for what ?
0
 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
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
 
LVL 48

Expert Comment

by:jpaulino
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
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
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
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
 
LVL 48

Expert Comment

by:jpaulino
Comment Utility
Not 100% sure but can you try ? I think is solves.
0
 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
Ok.

Thank you very much for your help.
0
 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
It works.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now