Example #1
0
        public bool checkThoiGian(thoigian tg)
        {
            SqlConnection con  = new SqlConnection(strQuery);
            DataTable     data = new DataTable();

            con.Open();
            SqlCommand cmd = new SqlCommand("select * from thoigian tg where days = @days and months= @months and years = @years ", con);

            cmd.Parameters.AddWithValue("@days", tg.Days);
            cmd.Parameters.AddWithValue("@months", tg.Months);
            cmd.Parameters.AddWithValue("@years", tg.Years);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);

            adapter.Fill(data);
            return(data.Rows.Count > 0);
        }
Example #2
0
        public void addThoiGian(thoigian tg)
        {
            SqlConnection con = new SqlConnection(strQuery);

            con.Open();
            if (!checkThoiGian(tg))
            {
                SqlCommand cmd = new SqlCommand("insert into thoigian (days,months,years) values (@days,@months,@years)", con);
                cmd.Parameters.AddWithValue("@days", tg.Days);
                cmd.Parameters.AddWithValue("@months", tg.Months);
                cmd.Parameters.AddWithValue("@years", tg.Years);
                cmd.ExecuteNonQuery();
            }

            con.Close();
        }