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

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;
}
主站蜘蛛池模板: 长武县| 临邑县| 收藏| 伊春市| 上虞市| 兴安盟| 多伦县| 聂拉木县| 驻马店市| 莲花县| 南皮县| 怀化市| 阿拉善右旗| 天津市| 潮州市| 盘锦市| 会宁县| 彭泽县| 尼木县| 兴化市| 邛崃市| 木里| 邹城市| 长武县| 伊宁县| 龙泉市| 绍兴市| 慈溪市| 泌阳县| 香格里拉县| 孝义市| 四子王旗| 那坡县| 平远县| 龙里县| 江孜县| 陆川县| 通城县| 六盘水市| 海丰县| 襄樊市|