error while moving code from dotnet1.1 to dotnet2.0?

Posted on 2006-05-12
Last Modified: 2010-08-05
Hello every one,
can any one plz help me in solving one problem that i found while moving my existing code on DotNet1.1 to DotNet2.0

Existing code just works fine.........there is no problem.........when i moved the code on dotnet2.0 i found one erorrr like this.............

"Conversion from string "2005/may/13 [13:00:00}" to Date is not valid"....
in existing code i have done the conversion of date like this.............

CDate(Format(DateTime.Now, "yyyy/MMM/dd [H:mm:ss]"))..............

how can  isolve this problem...........

Thanks for anyone's  help

Question by:shitbhar
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Can you show us some more code....the code snippet you are showing makes no sense!

        CDate(Format(DateTime.Now, "yyyy/MMM/dd [H:mm:ss]"))

    You're taking DateTime.Now (which is a VALID date to begin with), converting it a String in a custom format, and then converting it right back to a Date with CDate().


    Let's change an apple into an orange, and then back again into the same apple...

    Author Comment

    here is the code.....
    the problem is its working fine with dotnet1.1 but in dotnet 2.0 it is giving error while im reading data from sql server..the code looks like this.............

     Public Function LoginUser() As Long
            Dim HostName As String = System.Net.Dns.GetHostName
            Dim HostIP As String = GetIPAddress()
            Dim cn As New SqlConnection(connString)
            Dim cmd As New SqlCommand
                cmd.Connection = cn
                cmd.CommandText = "INSERT INTO [Login_History] (User_Id,Date_In,Store_Id,Host_Name,Host_IP) VALUES (" & Users.CurrentlyLoggedInUser.UserID & ",'" & CDate(Format(DateTime.Now.ToString, "yyyy/MM/dd [H:mm:ss]")) & "'," & Users.CurrentStoreID & ",'" & HostName & "','" & HostIP & "')"
                cmd.CommandText = "SELECT @@IDENTITY"
                LoginUser = CheckLongForDBNull(cmd.ExecuteScalar)
            Catch x As Exception
                MsgBox(x.ToString & " " & x.StackTrace)
            End Try
        End Function

    Hoping to get ansered from you very soon.......
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    (I don't know anything about SQL)

    But with regard to the formatting your date...

    Instead of:

        CDate(Format(DateTime.Now.ToString, "yyyy/MM/dd [H:mm:ss]"))

    I think you want:

        DateTime.Now.ToString("yyyy/MM/dd [H:mm:ss]")

    So the whole line would be:

        cmd.CommandText = "INSERT INTO [Login_History] (User_Id,Date_In,Store_Id,Host_Name,Host_IP) VALUES (" & Users.CurrentlyLoggedInUser.UserID & ",'" & DateTime.Now.ToString("yyyy/MM/dd [H:mm:ss]") & "'," & Users.CurrentStoreID & ",'" & HostName & "','" & HostIP & "')"

    Author Comment

    its still giving error..........thats not a solution...can i get information on dotnet framework2.0 documentation about how to format date function...?
    can u plz provide me that link so that im able to read the details.

    LVL 85

    Accepted Solution

    "thats not a solution"

    Sure it is.  I tested it out myself...

    Try this out:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim strDt As String = DateTime.Now.ToString("yyyy/MM/dd [H:mm:ss]")
        End Sub

    If you want the documentation then here it is...
    "Custom DateTime Format Strings"


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    754 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

    19 Experts available now in Live!

    Get 1:1 Help Now