Intermittant error: System.FormatException: Input string was not in a correct format.

C

cms0007

I keep getting the abvoe error trying to set a column to a value. The
values are being read from a file and can be an empty string or a
decimal number. The file is a text file. The column in the dataset
row is a decimal type. I read 10s to 1000s of rows from several files
and sometimes I get the error and sometimes do not. I never get the
error in debug and can read the same file and it processes sometimes
and sometimes does not due to this error. The errors seems to occur
on two lines of code below, postage fee or secfee. Whenever the error
occurs the it will always happen on the same field, either postage or
secfee but not both and will happen for the rest of the file read and
through subseqent file reads until the program is stopped and
restarted. This error did not always happen but has started recently.
Obviously something has changed but not sure what to look for.
From the code below the filerec object is a class I created to accept a
comma delimited string and to parse the data and then to return the
data through get properties. The get properties are in a base class
and the parsing functions are in a derived class.

The objNewRow object is a class derived from DataSet created from the
Data Adapter Connection wizard.


Code getting the error:

objNewRow["postagefee"] = ReturnStringValue(filerec.PostageFeeAmt);
objNewRow["secfee"] = ReturnStringValue(filerec.SECFeeAmt);

// returnstringvalue function

private object ReturnStringValue(string strTemp)
{
if(strTemp == null)
return System.DBNull.Value;
else
return strTemp;
}


//from filerec object:

protected string m_strPostageFeeAmt;
public string PostageFeeAmt{get{return m_strPostageFeeAmt;}}
protected string m_strSECFeeAmt;
public string SECFeeAmt{get{return m_strSECFeeAmt;} }


// Strings getting set inside filerec object

string[] strElements = strTradeRecord.Split(',');
....
m_strPostageFeeAmt = strElements[18];
m_strSECFeeAmt = strElements[19];


//Entire Error message:

Error for datalnk (12433265) in DoTradeFileInfoInsert():
System.FormatException: Input string was not in a correct format.
at System.Number.ParseDecimal(String s, NumberStyles style,
NumberFormatInfo info)
at System.Decimal.Parse(String s, NumberStyles style,
IFormatProvider provider)
at System.Convert.ToDecimal(String value, IFormatProvider provider)
at System.String.System.IConvertible.ToDecimal(IFormatProvider
provider)
at System.Convert.ToDecimal(Object value)
at System.Data.Common.DecimalStorage.Set(Int32 record, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object
value)Couldn't store <> in postagefee Co
lumn. Expected type is Decimal., System.Data -- at
System.Data.DataColumn.set_Item(Int32 record
, Object value)
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRow.set_Item(String columnName, Object value)
at
Sws.Bo.TradeUpload.FileReader.Client.CApplication.DoTradeFileInfoInsert(Int32
iRecordNumber,
Int32 iDataLnk, ReadTradeFile filerec)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top