官术网_书友最值得收藏!

How to do it...

  1. Create a new class called StarShip:
        public class Starship 
{

}
  1. To your class, add a new method that will set the maximum troop capacity of the StarShip class:
        public void SetMaximumTroopCapacity(int capacity) 
{

}
  1. Inside this method, add a trycatch clause that will attempt to set the maximum troop capacity, but for some reason, it will fail. Upon failure, it will write the error to the log table inside the database:
        try 
{
// Read current capacity and try to add more
}
catch (Exception ex)
{
string connectionString = "connection string goes here";
string sql = $"INSERT INTO tblLog (error, date) VALUES
({ex.Message}, GetDate())";
using (SqlConnection con = new
SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand(sql);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
}
throw ex;
}
主站蜘蛛池模板: 吴桥县| 田东县| 攀枝花市| 徐水县| 平潭县| 乐安县| 庆云县| 诏安县| 嘉善县| 襄汾县| 周至县| 汕尾市| 青冈县| 城步| 平遥县| 恩平市| 乌海市| 射洪县| 大余县| 乌拉特后旗| 青铜峡市| 星子县| 女性| 凌海市| 都匀市| 丽水市| 双柏县| 巴彦县| 亳州市| 墨脱县| 舒兰市| 临沭县| 封开县| 黑水县| 平凉市| 通渭县| 五峰| 武定县| 兴安县| 高要市| 木兰县|