3
Reply

Error formating number

Sousa Pambo

Sousa Pambo

Sep 6 2015 6:50 PM
361
Hi friends, I'm getting a error when I format number ( e.g 452 to 452.00), please see my code below
 
public double getValorPropinaPagoMesYear(string id_c, int mes, int year)
{
string sql = "select sum(valPago) as n from estudanteMensalidade where ficha_id='" + id_c + "' and ano=" + (year - 2000).ToString() + " and mes=" + mes.ToString();
using (SqlConnection cn = new SqlConnection(con.stringConexaoRH()))
{
try
{
cn.Open();
using (SqlCommand cm = new SqlCommand(sql, cn))
{
using (SqlDataReader rd = cm.ExecuteReader())
{
if (rd.Read())
{
try
{
return Convert.ToDouble(string.Format("{0:0.00}", rd[0]));
}
catch (Exception ex)
{
return 0;
}
}
else
{
return 0;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
 
Please Help! 
 

Answers (3)