Solved

Return Value of Date ans Null Function.

Posted on 2009-04-07
11
180 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
ID: 24090739
And that is for ?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24090782
Pardon me?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24090925
You will use that for a stored procedure or for what ?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Author Comment

by:emi_sastra
ID: 24090948
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
ID: 24091075
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
 
LVL 1

Author Comment

by:emi_sastra
ID: 24091179
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
ID: 24091214
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
ID: 24091307
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
ID: 24091457
Not 100% sure but can you try ? I think is solves.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24091539
Ok.

Thank you very much for your help.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24091572
It works.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to use odbc in vb to connect to ms sql 14 52
Web Form VB.Net  import CSV 4 36
VB 2005 Tooltips on Form Load Event 15 29
EF5: Question about Metadata Artifact Processing 4 15
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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