Esempio n. 1
0
        public bool Insert(WaterRescueKitBLL waterRescue)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(UserDAL.myconnstrng);

            try
            {
                string     sql = "INSERT INTO tbl_WaterRescue (waterRescue_no, Water_Rescue_Kit, Unit) VALUES (@waterRescue_no, @Water_Rescue_Kit, @Unit)";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@waterRescue_no", waterRescue.ID);
                cmd.Parameters.AddWithValue("@Water_Rescue_Kit", waterRescue.WaterRescueKit);
                cmd.Parameters.AddWithValue("@Unit", waterRescue.Unit);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                // If the query is executed successfully then the value to rows will be greaten than 0 else it will be less than 0
                if (rows > 0)
                {
                    // Query successful
                    isSuccess = true;
                }
                else
                {
                    // Query failed
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                // Throw message if any error occurs
                MessageBox.Show(ex.Message, "Insert data in Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
Esempio n. 2
0
        public bool Update(WaterRescueKitBLL waterRescue)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(UserDAL.myconnstrng);

            try
            {
                string     sql = "UPDATE tbl_WaterRescue SET Water_Rescue_Kit=@Water_Rescue_Kit, Unit=@Unit WHERE waterRescue_no=@waterRescue_no";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@Water_Rescue_Kit", waterRescue.WaterRescueKit);
                cmd.Parameters.AddWithValue("@Unit", waterRescue.Unit);
                cmd.Parameters.AddWithValue("@waterRescue_no", waterRescue.ID);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    // Query successful
                    isSuccess = true;
                }
                else
                {
                    // Query failed
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                // Throw message if any error occurs
                MessageBox.Show(ex.Message, "Update data in Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }