Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27355

VS 2012 [RESOLVED] Date Time conversion error

$
0
0
I am converting my program from Access to SQL. I am getting an error in the following code. It has to do with the DateTime conversion. I placed the message below the code. The table structure is as below.

What am i missing here ??

Code:


 If con.State = ConnectionState.Closed Then
            con.Open()
        End If
        MsgBox(Now().ToShortTimeString)
        Try
            Dim query As String = "Insert Into StudentLog ([UserName] , [StudentName] , [StudentID] , [DateDone] , [EmployerName] , [Postname] , [Activity] ,[TimeDone] ) Values ( @UserName , @StudentName , @StudentID , @DateDone , @EmployerName , @Postname , @Activity , @TimeDone )"
            Using conn As New SqlConnection(constr)
                Using cmd As New SqlClient.SqlCommand(query, conn)
                    cmd.Parameters.AddWithValue("@UserName", UserName)
                    cmd.Parameters.AddWithValue("@StudentName", StudentName)
                    cmd.Parameters.AddWithValue("@StudentID", StudentId)
                    cmd.Parameters.AddWithValue("@DateDone", Now().Date.ToShortDateString)
                    cmd.Parameters.AddWithValue("@EmployerName", EmployerName)
                    cmd.Parameters.AddWithValue("@PostName", Postname)
                    cmd.Parameters.AddWithValue("@Activity", Activity)
                    cmd.Parameters.AddWithValue("@TimeDone", Now().ToShortTimeString)
                    conn.Open()
                    cmd.ExecuteNonQuery()
                End Using
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If con.State = ConnectionState.Open Then
            con.Close()
        End If

Name:  DateTimeImage.png
Views: 21
Size:  24.7 KB

Name:  date time 2.png
Views: 16
Size:  6.1 KB
Attached Images
  

Viewing all articles
Browse latest Browse all 27355

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>