Esempio n. 1
0
        //Method to Update data in Database from application
        public bool Update(airlineInfoClass c)
        {
            //create a default return type and set its default value to false
            bool isSuccess = false;

            //create sql connection
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //Sql object to update data in database
                string sql = "UPDATE passenger_info SET Name=@Name, Email=@Email, DepartureFrom=@DepartureFrom, DestinationTo=@DestinationTo, PhoneReserve=@PhoneReserve, PassengerNo=@PassengerNo, PassportNo=@PassportNo, LuggageNo=@LuggageNo, TicketClass=@TicketClass, TripType=@TripType WHERE ReservationID=@ReservationID";
                //create sql command to insert data in this query
                SqlCommand cmd = new SqlCommand(sql, conn);
                //create Parameters to add value
                cmd.Parameters.AddWithValue("@Name", c.Name);
                cmd.Parameters.AddWithValue("@Email", c.Email);
                cmd.Parameters.AddWithValue("@DepartureFrom", c.DepartureFrom);
                cmd.Parameters.AddWithValue("@DestinationTo", c.DestinationTo);
                cmd.Parameters.AddWithValue("@PhoneReserve", c.PhoneReserve);
                cmd.Parameters.AddWithValue("@PassengerNo", c.PassengerNumber);
                cmd.Parameters.AddWithValue("@PassportNo", c.PassportNo);
                cmd.Parameters.AddWithValue("@LuggageNo", c.LuggageNo);
                cmd.Parameters.AddWithValue("@TicketClass", c.TicketClass);
                cmd.Parameters.AddWithValue("@TripType", c.TripType);
                cmd.Parameters.AddWithValue("@ReservationID", c.ReservationID);

                //open database connection
                conn.Open();

                //create integer value
                int rows = cmd.ExecuteNonQuery();

                //if query runs successfully, then value of rows > 0 else value of rows = 0
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Esempio n. 2
0
        //Method for Inserting Data into database from application
        public bool Insert(airlineInfoClass c)
        {
            //Create a default return type and setting value to false
            bool isSuccess = false;
            //1.Connect database
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //2. Create an SQL query to insert data
                string sql = "INSERT INTO passenger_info (Name, Email, DepartureFrom, DestinationTo, PhoneReserve, PassengerNo, PassportNo, LuggageNo, TicketClass, TripType) VALUES (@Name, @Email, @DepartureFrom, @DestinationTo, @PhoneReserve, @PassengerNumber, @PassportNo, @LuggageNo, @TicketClass, @TripType)";
                //Create SQL command using sql and conn
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Create parameters to add data
                cmd.Parameters.AddWithValue("@Name", c.Name);
                cmd.Parameters.AddWithValue("@Email", c.Email);
                cmd.Parameters.AddWithValue("@DepartureFrom", c.DepartureFrom);
                cmd.Parameters.AddWithValue("@DestinationTo", c.DestinationTo);
                cmd.Parameters.AddWithValue("@PhoneReserve", c.PhoneReserve);
                cmd.Parameters.AddWithValue("@PassengerNumber", c.PassengerNumber);
                cmd.Parameters.AddWithValue("@PassportNo", c.PassportNo);
                cmd.Parameters.AddWithValue("@LuggageNo", c.LuggageNo);
                cmd.Parameters.AddWithValue("@TicketClass", c.TicketClass);
                cmd.Parameters.AddWithValue("@TripType", c.TripType);


                //open connection
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //If query is successful, value of rows > zero else value will be zero
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Esempio n. 3
0
        //method to delete data from Database
        public bool Delete(airlineInfoClass c)
        {
            //create default return value and set value to false
            bool isSuccess = false;

            //create SQL Connection
            SqlConnection conn = new SqlConnection(myconnstrng);

            try
            {
                //Sql object to delete data
                string sql = "DELETE FROM passenger_info WHERE ReservationID=@ReservationID";

                //SQL command
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@ReservationID", c.ReservationID);

                //open sql connection
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //if the query runs successfully, then value of rows > 0 else values = 0
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }