我正在尝试将一个select语句的结果存储在C#变量中,但是出现了以下错误:
"指定的转换无效"
运行时遇到了这个错误。我不确定该如何解决,请帮忙。
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
SqlCommand cmd1 = new SqlCommand("select cast(round(sum(CAST(AvgNumbers AS numeric(12,2))),2) as decimal(12,2)) AS [Average Days] from MainTable ", con1);
cmd1.Connection = con1;
con1.Open();
Int32 result = (Int32)cmd1.ExecuteScalar();
con1.Close();