Adding a sum of numeric values of a column, i am getting an error “Input String is not in correct format”
Value in Excel column: 192.00 EA
I need to get only the numeric value 192.00 from it.It works if there is only numeric value but if an alphabet like above ‘EA’ is present it is giving an error
Using: – Works fine if only number is present
" outDataTable.AsEnumerable.Sum(Function(x) Convert.ToDouble(x(outDataTable.Columns(14).ColumnName.ToString()).ToString.Trim) ).ToString"
Tried using regex.replace - Its giving column not present error.
You should pull out just the 192.00 EA and convert it from object to string. This is as simple as pulling it from your datatable as a specific item and appending .ToString at the end.
Then there’s no need to use lambda as that makes it a bit more complicated. Simply use Regex.Match instead. The pattern \d+\.{0,1}\d* should match anything and include the decimal (if it exists). So it would look something like this:
I am using it in the Sum function to add all the column values of multiple rows, filtered by a condition in FilterDataTable. The FilterDataTable fetches all the rows of a particular day, so the number of rows is different in each case. Pulling each column value and converting it into String is bit tedious.