私は C# にまったく慣れていないので、ご容赦ください。
private static string GetFormattedValue(string dataType, dynamic cellValue)
{
string formattedCellValue = string.Empty;
if (cellValue == null)
cellValue = DBNull.Value;
if (dataType == "STRING")
{
formattedCellValue = string.Format("'{0}',", cellValue);
}
else if (dataType == "NUMBER")
{
if (string.IsNullOrEmpty(Convert.ToString(cellValue)))
cellValue = 0;
formattedCellValue = string.Format("'{0}',", cellValue.ToString("F17"));
}
else if (dataType == "DATE")
{
formattedCellValue = string.Format("'{0}',", cellValue);
}
else
{
formattedCellValue = string.Format("'{0}',", cellValue.ToString("F17"));
}
return formattedCellValue;
がdataType
NUMBER でcellValue
整数の場合、「string.ToString(System.IFormatProvider) に一致する最適なオーバーロード メソッドには無効な引数があります」というエラーが表示されます。
cellValue
多くの場合、「F17」がないと、科学的表記法として返される非常に小さい数値 (これにより、別のエラーが発生します) だけでなく、上記のエラーの原因となる整数も返されます。
これは私のコードではありません。実行しているだけで、ステップ実行するのに十分なことがわかっています。cellValue
整数かどうかを判断するために読み取ることができるかどうかを判断する方法はありますか? または他のより良い提案はありますか?