none
Input string was not in a correct format

    Question

  • somebody, please could tell me where is mi mistake in this problem?? I don't understand why is trying to change from string to Int32..

    here's the error I am getting..

    Any ideas??, suggestions?? thanks in advance

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

    Source Error:

    Line 103:    objComm.Parameters.Add(parameterPosition)
    Line 104:    
    Line 105:    objComm.ExecuteNonQuery() 'Execute the UPDATE query
    Line 106:    
    Line 107:    objConn.Close() 'Close the connection
    Stack Trace:

    [FormatException: Input string was not in a correct format.]
       System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2753203
       System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt) +119
       System.Decimal.Parse(String s, NumberStyles style, IFormatProvider provider) +37
       System.Convert.ToDecimal(String value, IFormatProvider provider) +50
       System.String.System.IConvertible.ToDecimal(IFormatProvider provider) +10
       System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +2562352
       System.Data.OleDb.OleDbParameter.CoerceValue(Object value, NativeDBType destinationType) +296
    
    [FormatException: Failed to convert parameter value from a String to a Int32.]
       System.Data.OleDb.OleDbParameter.CoerceValue(Object value, NativeDBType destinationType) +358
       System.Data.OleDb.OleDbParameter.BindParameter(Int32 index, Bindings bindings) +188
       System.Data.OleDb.OleDbCommand.CreateAccessor() +221
       System.Data.OleDb.OleDbCommand.InitializeCommand(CommandBehavior behavior, Boolean throwifnotsupported) +180
       System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +36
       System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +188
       System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +112
    ....

    Sub dgPopStations_Update(sender As Object, e As DataGridCommandEventArgs)

    Dim iStationID As Integer = e.Item.Cells(1).Text ' Determine the StationID
    Dim iBandID As Integer = CType(e.Item.FindControl("lstBands"), DropDownList).SelectedItem.Value
    Dim strBandName As String = CType(e.Item.FindControl("lstBands"),DropDownList).SelectedItem.Text
    Dim strStationName As String = CType(e.Item.FindControl("txtStationName"), TextBox).Text
    Dim strPosition As String = CType(e.Item.FindControl("txtPositionStation"), TextBox).Text

    Dim strSQL As String = "UPDATE [tblStations] SET [StationPosition] = @StationPosition , [StationName] = @StationName , [BandId] = @BandID WHERE [StationID] = @StationID"

    ObjConn.Open()

    Dim objComm As OleDbCommand = New OleDbCommand(strSQL, ObjConn)

    objComm.CommandType = CommandType.Text

    'Add parameters to the SQL Query

    Dim parameterStationID As OleDbParameter = New OleDbParameter("@StationID", OleDbType.UnsignedBigInt)
    parameterStationID.Value = iStationID
    objComm.Parameters.Add(parameterStationID)

    Dim parameterBandID As OleDbParameter = New OleDbParameter("@BandID", OleDbType.UnsignedBigInt)
    parameterBandID.Value = iBandID
    objComm.Parameters.Add(parameterBandID)

    Dim parameterStationName As OleDbParameter = New OleDbParameter("@StationName", OleDbType.VarWChar, 100)
    parameterBandID.Value = strBandName
    objComm.Parameters.Add(parameterStationName)

    Dim parameterPosition As OleDbParameter = New OleDbParameter("@StationPosition", OleDbType.VarWChar, 50)
    parameterBandID.Value = strPosition
    objComm.Parameters.Add(parameterPosition)

    objComm.ExecuteNonQuery() 'Execute the UPDATE query
    objConn.Close() 'Close the connection

    Friday, January 27, 2006 3:15 PM

All replies

  • Try not specifying the OleDbType of your parameters; let the parameter infer the correct data type from the value you are passing in.
    Friday, January 27, 2006 5:11 PM
  • Try setting just the Name and Value of the Parameters. If these all are just Input parameters, then you don't even need to set the size. The type, size, etc will get inferred from the Value.

    However, you do need to be careful about the dataype mismatches from the backend server where you are trying to Update/Insert the data. In some cases, the backend server may not support certain coercions.

    Disclaimer: This posting is provided "AS IS" with no warranties, and confers no rights

    Friday, January 27, 2006 11:09 PM
  • Hello guys!!.. thanks a lot for your reply... I have followed your advice, but there's a warning  even before run time...

    Dim parameterPosition As OleDbParameter = New OleDbParameter("@StationPosition")...

    when i use this declaration I got this warning:

    Overload resolution failed because no accessible 'New' accepts this number of arguments.

    ... now according to .NET a data type Variant is assumed when there's no type specified... so what i tried to set this data type directly..for all the parameters

    Dim parameterPosition As OleDbParameter = New OleDbParameter("@StationPosition", OleDbType.Variant)

    and now I am getting this error

    Exception Details: System.Data.OleDb.OleDbException: Parameter @BandID has no default value.

    Source Error:

    Line 103:    objComm.Parameters.Add(parameterPosition)
    Line 104:    
    Line 105:    objComm.ExecuteNonQuery() 'Execute the UPDATE query
    Line 106:    
    Line 107:    objConn.Close() 'Close the connection

    Source File: C:\Documents and Settings\vazquez\My Documents\Visual Studio 2005\WebSites\Eckerle1\Default8.aspx    Line: 105

    Stack Trace:

    [OleDbException (0x80040e10): Parameter @BandID has no default value.]
       System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +177
       System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +194
    

    ...
    Monday, January 30, 2006 10:04 AM
  • The first error you are getting the key. Take a look at the constructors for OleDbParameter to get an idea of what you need to be passing. The constructor you are using is expecting the first argument to be the name, and the second argument to be the value. So you are basically passing OleDbType.Variant as the value of the parameter, which is not what you want. What you need to do instead is pass the name and the value of the parameter, and the type as the third parameter, but only if it is needed (most of the time it isnt).
    Monday, January 30, 2006 5:52 PM