I have a web form in which users input data into text boxes. There are a myriad of textboxes and most of them can be left blank. I have a date field (textbox) and when left blank, it gives me the following error message:
============================
Cast from string "" to type 'Date' is not valid.
Source Error:
Line 83:
Line 84: Sub ImageButton_Click(sender As Object, e As ImageClickEventArgs)
Line 85: If Add(txtAcct.Text, txtName.Text, txtAddr.Text, txtCity.Text, ddlState.SelectedItem.Text, ddlAType.SelectedItem.Text, txtADate.Text, txtCode.Text, txtComm1.Text, txtComm2.Text, ddlBy.SelectedItem.Text) > 0
Line 86: Message.Text = "New Account created successfully!"
Line 87: Else
Stack Trace:
[InvalidCastException: Cast from string "" to type 'Date' is not valid.]
Microsoft.VisualBasic.CompilerServices.DateType.FromString(String Value, CultureInfo culture)
Microsoft.VisualBasic.CompilerServices.DateType.FromString(String Value)
ASP.EnterCassAccount_aspx.ImageButton_Click(Object sender, ImageClickEventArgs e) in c:\inetpub\System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
[/red]
===================================
Here is some of my code that might help:
=============================
Function AddCass(ByVal Acct As String, ByVal Name As String, ByVal _
Addr As String, ByVal City As String, ByVal State As String, _
ByVal AType As String, ByVal ADate As Date, _
ByVal Code As String, ByVal Comm1 As String, _
ByVal Comm2 As String, ByVal By As String) As Integer
...
sqlCommand.Parameters.Add("@ADate", System.Data.SqlDbType.SmallDateTime).Value = ADate
[/blue]
============================
I can't seem to figure out what is going wrong...
============================
Cast from string "" to type 'Date' is not valid.
Source Error:
Line 83:
Line 84: Sub ImageButton_Click(sender As Object, e As ImageClickEventArgs)
Line 85: If Add(txtAcct.Text, txtName.Text, txtAddr.Text, txtCity.Text, ddlState.SelectedItem.Text, ddlAType.SelectedItem.Text, txtADate.Text, txtCode.Text, txtComm1.Text, txtComm2.Text, ddlBy.SelectedItem.Text) > 0
Line 86: Message.Text = "New Account created successfully!"
Line 87: Else
Stack Trace:
[InvalidCastException: Cast from string "" to type 'Date' is not valid.]
Microsoft.VisualBasic.CompilerServices.DateType.FromString(String Value, CultureInfo culture)
Microsoft.VisualBasic.CompilerServices.DateType.FromString(String Value)
ASP.EnterCassAccount_aspx.ImageButton_Click(Object sender, ImageClickEventArgs e) in c:\inetpub\System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
[/red]
===================================
Here is some of my code that might help:
=============================
Function AddCass(ByVal Acct As String, ByVal Name As String, ByVal _
Addr As String, ByVal City As String, ByVal State As String, _
ByVal AType As String, ByVal ADate As Date, _
ByVal Code As String, ByVal Comm1 As String, _
ByVal Comm2 As String, ByVal By As String) As Integer
...
sqlCommand.Parameters.Add("@ADate", System.Data.SqlDbType.SmallDateTime).Value = ADate
[/blue]
============================
I can't seem to figure out what is going wrong...