コード例 #1
0
        public IList <AusHoliday> GetAusHoliday()
        {
            var           listRepDayOff = new List <AusHoliday>();
            SqlConnection conn          = new SqlConnection();

            conn.ConnectionString = CONNSTRING;
            var strSqlContactStmt = @"SELECT Id, Year, Month, HolidayDate, CreatedDate FROM dbo.AusHoilday";

            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = strSqlContactStmt;
                cmd.Connection  = conn;
                conn.Open();

                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var repDayfff = new AusHoliday()
                    {
                        Id          = Convert.ToInt32(reader["Id"]),
                        CreatedDate = Convert.ToDateTime(reader["CreatedDate"]),
                        Year        = Convert.ToInt32(reader["Year"]),
                        HolidayDate = Convert.ToDateTime(reader["HolidayDate"]),
                        Month       = Convert.ToInt32(reader["Month"]),
                    };


                    listRepDayOff.Add(repDayfff);
                }
            }
            conn.Close();


            return(listRepDayOff);
        }
コード例 #2
0
        public void InsertHolidayByMonth(AusHoliday obj)
        {
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = CONNSTRING;
            var strSqlContactStmt = @"INSERT INTO AusHoilday(Year, Month, HolidayDate, CreatedDate) 
                                     VALUES(@year, @month, @holidayDate,CURRENT_TIMESTAMP)";

            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.Connection = conn;
                conn.Open();
                cmd.Parameters.Add("@year", SqlDbType.Int).Value             = obj.Year;
                cmd.Parameters.Add("@month", SqlDbType.Int).Value            = obj.Month;
                cmd.Parameters.Add("@holidayDate", SqlDbType.DateTime).Value = obj.HolidayDate;
                cmd.CommandText = strSqlContactStmt;
                cmd.ExecuteNonQuery();
            }
            conn.Close();
        }