Esempio n. 1
0
        //Insert data into database
        public bool Insert(NotAvailableTime a)
        {
            bool isSuccess = false;

            //connect database
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //sql query
                string sql = "INSERT INTO NAT(stype, sitems, stime, etime, date) VALUES(@stype, @sitems, @stime, @etime, @date)";
                //Slq command using sql & conn
                SqlCommand cmd = new SqlCommand(sql, conn);
                //create parameter to add data
                cmd.Parameters.AddWithValue("@stype", a.stype);
                cmd.Parameters.AddWithValue("@sitems", a.sitems);
                cmd.Parameters.AddWithValue("@stime", a.stime);
                cmd.Parameters.AddWithValue("@etime", a.etime);
                cmd.Parameters.AddWithValue("@date", a.date);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
            return(isSuccess);
        }
Esempio n. 2
0
        //method delete

        public bool Delete(NotAvailableTime a)
        {
            bool isSuccess = false;
            //sql connection
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //Sql query
                string sql = "DELETE FROM NAT WHERE NATno=@NATno";

                //Create sql Command
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@NATno", a.NATno);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }