コード例 #1
0
        public NailDate GetNailDateById(int nailDateId)
        {
            string   query = "select * from NailDates where Id >= @id";
            NailDate dates = null;

            // create connection and command
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnectionSctring"].ConnectionString))
                using (SqlCommand cmd = new SqlCommand(query, cn))
                {
                    cmd.Parameters.Add("@id", SqlDbType.Int).Value = nailDateId;
                    cn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    try
                    {
                        dr.Read();
                        dates = NailDate.Parse(dr);
                    }
                    catch (System.Exception ex)
                    {
                        LastErrorMessage = ex.Message;
                    }
                    finally
                    {
                        cn.Close();
                    }
                }
            return(dates);
        }
コード例 #2
0
        private List <NailDate> GetNailDatesSinceDate(DateTime sinceTime)
        {
            string query = "select * from NailDates where StartTime >= @DateFrom";
            var    dates = new List <NailDate>();

            // create connection and command
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnectionSctring"].ConnectionString))
                using (SqlCommand cmd = new SqlCommand(query, cn))
                {
                    cmd.Parameters.Add("@DateFrom", SqlDbType.DateTime).Value = sinceTime;
                    cn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        dates.Add(NailDate.Parse(dr));
                    }
                    cn.Close();
                }
            return(dates);
        }
コード例 #3
0
        public List <NailDate> GetNailDatesForTimeRange(DateTime sinceTime, DateTime tillTime)
        {
            string query = "select * from NailDates where StartTime >= @sinceTime and StartTime <=@tillTime order by StartTime";
            var    dates = new List <NailDate>();

            // create connection and command
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnectionSctring"].ConnectionString))
                using (SqlCommand cmd = new SqlCommand(query, cn))
                {
                    cmd.Parameters.Add("@sinceTime", SqlDbType.DateTime).Value = sinceTime;
                    cmd.Parameters.Add("@tillTime", SqlDbType.DateTime).Value  = tillTime.AddDays(1);
                    cn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        dates.Add(NailDate.Parse(dr));
                    }
                    cn.Close();
                }
            return(dates);
        }