I have a query where I receive information from a database in DataTable
:
DataTable estimateCalculation = new DataTable();
estimateCalculation = db.ExeSQLEstimate("usp_Contracted_Calculation", param1, param2);
So now I get values as:
var averageContractedAmount = (from DataRow dr in estimateCalculation.Rows select (decimal)dr["AverageContractedAmount"]).FirstOrDefault().ToString("C");
But in some scenarios dr
can be empty so it throws an exception
System.InvalidCastException: 'The specified conversion is not valid
How can I validate if dr
returns null, to not try to convert it to decimal?