InvalidCastException: Conversion from string to type 'Double' is not valid.

  • Thread starter Thread starter falcon_426
  • Start date Start date
F

falcon_426

Guest
I keep getting this error "InvalidCastException: Conversion from string to type 'Double' is not valid." whenever I try and run this piece of code. Could someone explain to me where it is trying to make a conversion to double? No matter what I do to my input string, I get the error.

Here is the stack trace:

Input string was not in a correct format.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:


Line 144: Dim esys As String



Line 145:



Line 146: If Mid(EditCircuit, (EditCircuit - 3), 1) = "-" Then



Line 147: esys = Mid(EditCircuit, Len(EditCircuit - 2))



Line 148: GoTo CheckSys2

Source File: C:\Inetpub\wwwroot\DpsCrecords\AddEdit\EditTableCircuits.aspx.vb Line: 146

Stack Trace:


[FormatException: Input string was not in a correct format.]



Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String Value, NumberFormatInfo NumberFormat) +204



Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value, NumberFormatInfo NumberFormat) +89







[InvalidCastException: Conversion from string "HAY-KCI703-01" to type 'Double' is not valid.]



Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value, NumberFormatInfo NumberFormat) +225



Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value) +6



AddEdit.EditTables.Datagrid1_UpdateCommand(Object source, DataGridCommandEventArgs e) in C:\Inetpub\wwwroot\DpsCrecords\AddEdit\EditTableCircuits.aspx.vb:146



System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) +108



System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +499



System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37



System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +123



System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37



System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118



System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166



System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10



System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13



System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36



System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565




Here is the code section that is giving me the error:


Private Sub Datagrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Datagrid1.UpdateCommand 'Copy for editing...

dsb = Session("dsb")




Dim rownumber As Int16 = e.Item.ItemIndex 'Get This First

Dim EditTable As String = Session("EditTable") 'We need a fresh load before edit change...

NewEditToUpper()


gridload()





Dim NewEditItem1 As String = TBoxEditItem1.Text If NewEditItem1 = "" Then GoTo EndUpdateCommand 'Nulls not allowed

If NewEditItem1 < "0" Then GoTo EndUpdateCommand 'Spaces and Punct not allowed



Dim NewEditItem2 As String = TBoxEditItem2.Text If NewEditItem2 = "" Then GoTo EndUpdateCommand 'Nulls not allowed

If NewEditItem2 < "0" Then GoTo EndUpdateCommand 'Spaces and Punct not allowed





Select Case EditTable

Case "Circuits" Dim dgitem As DataGridItem = Datagrid1.Items(rownumber)

Dim EditSystem As String = dgitem.Cells(2).Text Dim EditCircuit As String = UCase(dgitem.Cells(3).Text)

If Len(EditCircuit) < 7 Then GoTo EndUpdateCommand 'First Check the System Designation

Dim esys As String

If Mid(EditCircuit, (EditCircuit - 3), 1) = "-" Then


esys = Mid(EditCircuit, Len(EditCircuit - 2))


GoTo CheckSys2 End If







If Mid(EditCircuit, (EditCircuit - 2), 1) = "-" Then


esys = Mid(EditCircuit, Len(EditCircuit - 1))


GoTo CheckSys2 End If




GoTo EndUpdateCommand 'len error Must be 2 or 3 places, preceeded by "-"






editsystem = RTrim(editsystem)

EditCircuit = RTrim(EditCircuit)








Continue reading...
 
Back
Top