Hey, my app parses numerous txt files in a directory that are almost all formatted identically, then inserts the values into columns of my sql db. However, there are a few files that the app has come across where a value is 'blank' instead of '0.0', so the application fails stating that it cannot convert that value to numeric.
Is there a way I could change the following code to say what says AND also add 'IF value is blank, then import 0.0 instead?
EDIT: The following code seems to get my pass my error, however now I have all columns showing as numbers. if it is text, it inputs "0" in its place...
string[] values = line.Split(new[] { ',' });
for (int i = 0; i < values.Length - 1; i++)
{
SqlParameter param = insertCommand.Parameters[i];
decimal value;
if (values[i] == null || values[i] == "")
{
value = 0.000m;
}
else
{
if (!decimal.TryParse(values[i], out value))
{
// param.Value = decimal.TryParse(values[i], out value) ? value : 0;
param.Value = values[i];
}
}
param.Value = value;
}