I'm trying to pass values in a SessionState from one page to another and then post them to a SQL database. When I click on the submit button on my submit page, I get this error:
Failed to convert parameter value from a String to a DateTime.
Here is my submit page:
Can anyone help me to figure out what I'm not seeing. I've verified that all of the input matches what I'm looking for on the SQL side.
Failed to convert parameter value from a String to a DateTime.
Here is my submit page:
Code:
Imports System.Data.SqlClient
Imports System.Data
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim opnumber As String = CType(Session.Item("opnumber"), String)
Dim exceptiondate As DateTime = CType(Session.Item("exceptiondate"), DateTime)
Dim stime As DateTime = CType(Session.Item("starttime"), DateTime)
Dim etime As DateTime = CType(Session.Item("endtime"), DateTime)
Dim hours As String = CType(Session.Item("hours"), String)
Dim minutes As String = CType(Session.Item("minutes"), String)
Dim exceptioncode As String = CType(Session.Item("exceptioncode"), String)
Dim submittedby As String = CType(Session.Item("submittedby"), String)
opnumLabel.Text = opnumber
exceptdateLabel.Text = exceptiondate
starttimeLabel.Text = stime
endtimeLabel.Text = etime
hourdurLabel.Text = hours
mindurLabel.Text = minutes
codeLabel.Text = exceptioncode
approvedbyLabel.Text = submittedby
End Sub
Protected Sub sqlsubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles sqlsubmitButton.Click
InsertRow()
End Sub
Public Sub InsertRow()
Dim myConnectionString As String = "Initial Catalog=mdr;Data Source=xxxxxx;uid=xxxxx;password=xxxxxxxx;"
Dim myConnection As New SqlConnection(myConnectionString)
Dim commandText As String = _
"insert into Exceptions (employeenumber, exceptiondate, starttime, endtime, duration, code, approvedby) " & _
"values(@employeenumber, @exceptiondate, @starttime, @endtime, @duration, @code, @approved)"
Using connection As New SqlConnection(myConnectionString)
Dim command As New SqlCommand(commandText, connection)
command.Parameters.Add("@employeenumber", SqlDbType.VarChar)
command.Parameters("@employeenumber").Value = "opnumber"
command.Parameters.Add("@exceptiondate", SqlDbType.DateTime)
command.Parameters("@exceptiondate").Value = "exceptiondate"
command.Parameters.Add("@starttime", SqlDbType.DateTime)
command.Parameters("@starttime").Value = "starttime"
command.Parameters.Add("@endtime", SqlDbType.DateTime)
command.Parameters("@endtime").Value = "endtime"
command.Parameters.Add("@duration", SqlDbType.VarChar)
command.Parameters("@duration").Value = "hours, minutes"
command.Parameters.Add("@code", SqlDbType.VarChar)
command.Parameters("@code").Value = "exceptioncode"
command.Parameters.Add("@approved", SqlDbType.VarChar)
command.Parameters("@approved").Value = "submittedby"
Try
connection.Open()
Dim rowsAffected As Integer = command.ExecuteNonQuery()
Catch ex As Exception
myerrormessageLabel.Text = ex.Message
End Try
thankyouLabel.Text = "Your Data Has Been Submitted"
End Using
End Sub
Protected Sub cancelinputButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cancelinputButton.Click
Response.Redirect("Default.aspx")
End Sub
End Class
Comment