Пример #1
0
        public bool Insert(MotorizedVehicleBLL vehicle)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(UserDAL.myconnstrng);

            try
            {
                string     sql = "INSERT INTO tbl_Vehicle (vehicle_no, Motorized_Vehicle, Unit) VALUES (@vehicle_no, @Motorized_Vehicle, @Unit)";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@vehicle_no", vehicle.ID);
                cmd.Parameters.AddWithValue("@Motorized_Vehicle", vehicle.MotorizedVehicle);
                cmd.Parameters.AddWithValue("@Unit", vehicle.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);
        }
Пример #2
0
        public bool Update(MotorizedVehicleBLL vehicle)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(UserDAL.myconnstrng);

            try
            {
                string     sql = "UPDATE tbl_Vehicle SET Motorized_Vehicle=@Motorized_Vehicle, Unit=@Unit WHERE vehicle_no=@vehicle_no";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@Motorized_Vehicle", vehicle.MotorizedVehicle);
                cmd.Parameters.AddWithValue("@Unit", vehicle.Unit);
                cmd.Parameters.AddWithValue("@vehicle_no", vehicle.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);
        }