我在我的网络表单上收到以下错误消息:
Cast from string "" to type 'Date' is not valid.
我假设这是因为这条线(但我的假设可能不正确):
command.Parameters.Add(New SqlParameter("col3", SqlDbType.DateTime, 8)).Value = some_date_parameter
在一个函数中:
Function ProcessAction(ByVal col1 As Integer, ByVal col2 As String, ByVal col3 As Date, ByVal col4 As Integer, ByVal col5 As String) as something
'...
command.Parameters.Add(New SqlParameter("@col1", SqlDbType.Int, 4)).Value = col1
command.Parameters.Add(New SqlParameter("@col2", SqlDbType.VarChar, 255)).Value = col2
command.Parameters.Add(New SqlParameter("@col3", SqlDbType.DateTime, 8)).Value = col3
command.Parameters.Add(New SqlParameter("@col4", SqlDbType.Int, 4)).Value = col4
command.Parameters.Add(New SqlParameter("@col5", SqlDbType.VarChar, 255)).Value = col5
'...
Return something
End Function
通过按钮调用:
Sub ButtonClick(ByVal Source As Object, ByVal E As EventArgs)
'...
structRecord = ProcessAction(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text)
'...
End Sub
在哪里structRecord
:
Public Structure structRecord
Public col1 As Integer
Public col2 As String
Public col3 As Date
Public col4 As Integer
Public col5 As String
End Structure
实际错误在运行时显示在此行中,位于ButtonClick
:
structRecord = ProcessAction(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text)
如何纠正这个问题?我基本上希望允许用户继续使用 webapp 的其余部分,即使它TextBox3.Text
是空的。