Pho3nix
The Legend
Hi guys,
I am currently doing some validation on Excel Files which get imported into a SSIS package.
Now the issue I am having is C# validates strings as integers when this isn't actually possible resulting in the package failing.
Sample of the Code is :
I am currently doing some validation on Excel Files which get imported into a SSIS package.
Now the issue I am having is C# validates strings as integers when this isn't actually possible resulting in the package failing.
Sample of the Code is :
Code:
foreach (SourceValidation sourceValidation in sourceValidations)
{
switch (sourceValidation.ColumnDatatype)
{
case "String" :
result = true;
break;
case "Integer":
if ((!string.IsNullOrEmpty(row.GetCell(columnIndex).StringValue) && (!int.TryParse(row.GetCell(columnIndex).StringValue, out tempInt))))
{
result = false;
throw new Exception(string.Format("The column type '{0}' is not correct. The correct type should be '{1}' for the Column '{2}'. Row number {3}", row.GetCell(columnIndex).StringValue, sourceValidation.ColumnDatatype.ToString(), sourceValidation.ColumnName.ToString(),(rowIndex-1).ToString()));
}
break;
case "Date":
if ((!string.IsNullOrEmpty(row.GetCell(columnIndex).StringValue) && (!DateTime.TryParse(row.GetCell(columnIndex).DateTimeValue.ToString(), out tempDate))))
{
result = false;
throw new Exception(string.Format("The column type '{0}' is not correct. The correct type should be '{1}' for the Column '{2}'.Row number {3}", row.GetCell(columnIndex).StringValue, sourceValidation.ColumnDatatype.ToString(), sourceValidation.ColumnName.ToString(), (rowIndex - 1).ToString()));
}
break;
case "Decimal":
if ((!string.IsNullOrEmpty(row.GetCell(columnIndex).StringValue) && (!decimal.TryParse(row.GetCell(columnIndex).StringValue, out tempDec))))
{
result = false;
throw new Exception(string.Format("The column type '{0}' is not correct. The correct type should be '{1}' for the Column '{2}'.Row number {3}", row.GetCell(columnIndex).StringValue, sourceValidation.ColumnDatatype.ToString(), sourceValidation.ColumnName.ToString(),(rowIndex - 1).ToString()));
}
break;
}
tempInt = 0;
tempDec = 0;
tempDate = DateTime.Now;
columnIndex++;
}
rowIndex++;
}