?
Solved

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

Posted on 2006-05-12
7
Medium Priority
?
269 Views
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

Thanks,
Bharat.
0
Comment
Question by:shitbhar
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16671707
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...
0
 

Author Comment

by:shitbhar
ID: 16671957
hi,
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
        Try
            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 & "')"
            cn.Open()
            cmd.ExecuteNonQuery()
            cmd.CommandText = "SELECT @@IDENTITY"
            LoginUser = CheckLongForDBNull(cmd.ExecuteScalar)
        Catch x As Exception
            MsgBox(x.ToString & " " & x.StackTrace)
        Finally
            cn.Close()
            cmd.Dispose()
            cn.Dispose()
        End Try
    End Function

Hoping to get ansered from you very soon.......
Thanks,
Bharat.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16672116
(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 & "')"
0
 

Author Comment

by:shitbhar
ID: 16672196
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.

thanks,
Bharat.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 80 total points
ID: 16672209
"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]")
        MsgBox(strDt)
    End Sub

If you want the documentation then here it is...
DateTime.ToString(String) http://msdn2.microsoft.com/en-us/library/zdtaw1bw(VS.80).aspx
"Custom DateTime Format Strings" http://msdn2.microsoft.com/en-US/library/8kb3ddd4.aspx

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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.
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

864 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