Webフォームに次のエラーメッセージが表示されます。
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)
この問題はどのように修正できますか?基本的に、ユーザーがTextBox3.Text
空のままになっている場合でも、残りのWebアプリを続行できるようにします。