データベースが結果セットを返す限り、私のコードは問題なく機能します。何も返さない場合は壊れて、次のエラーが発生します。
System.FormatException: Input string was not in a correct format.
これが私のコードです:
DataTable data = GeneralFunctions.GetData( query );
object sumObject;
sumObject = data.Compute( "Sum(Minutes_Spent)", "" );
if ( reportType == 1 )
{
RepeaterPCBillable.DataSource = data;
RepeaterPCBillable.DataBind();
LabelPCBillable.Text = ParseTime( int.Parse( sumObject.ToString() ) ) == null
? ParseTime( int.Parse( sumObject.ToString() ) )
: ""; // ERROR HERE
}
else
{
RepeaterDTSTBillable.DataSource = data;
RepeaterDTSTBillable.DataBind();
LabelDTSTBillable.Text = ParseTime( int.Parse( sumObject.ToString() ) ) == null
? ParseTime( int.Parse( sumObject.ToString() ) )
: "";
}
ParseTime:
protected string ParseTime ( int TotalMinutes )
{
int hours = TotalMinutes / 60;
int minutes = TotalMinutes % 60;
if ( hours == 0 )
{
return String.Format( "{0} minutes", minutes );
}
else if ( hours == 1 )
{
return String.Format( "{0} hour and {1} minutes", hours, minutes );
}
else if ( hours > 1 )
{
return String.Format( "{0} hours and {1} minutes", hours, minutes );
}
else
{
return "";
}
}