//由于要多次统计表里面多个字段的(count,sum,avg之类),所以考虑 打开一次数据库,等所有的计算结束了,一次性关闭
public int SelectSingleValue(string tempStrSQL)
{
   try
   {
int intNumber = 0;

if ((myConnection.State == ConnectionState.Broken) || (myConnection.State == ConnectionState.Closed) )//调试F11到在这里出了问题,直接到下面的catch里面了,为什么
//我的意思是:如果数据库有连接,就不再打开了,如果没有连接,就OPen
{
this.myConnection = new SqlConnection(connectionString);
myConnection.Open();
}
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = tempStrSQL;
object sumNumber = myCommand.ExecuteScalar();
if((sumNumber is DBNull) == false)
{
intNumber = int.Parse((sumNumber).ToString());
}

return intNumber;
}
   catch(Exception e)
   {
throw new Exception(e.Message);
   }
}