Exemple #1
0
        public void update(UpdateABus bus)
        {
            SqlConnection conn;
            SqlCommand    cmd;

            conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\project of c# summer 2020\FinalExam\FinalExam-BasharJebry\ABCTourDB_BasharJebry.mdf;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework");
            conn.Open();
            cmd = new SqlCommand("Update BusInfo set Model=@Model, Make=@Make ,NoOfSeats=@NoOfSeats where BusId=@BusId", conn);
            cmd.Parameters.AddWithValue("@BusId", bus.BusId);
            cmd.Parameters.AddWithValue("@Make", bus.Make);
            cmd.Parameters.AddWithValue("@Model", bus.Model);
            cmd.Parameters.AddWithValue("@NoOfSeats", bus.NoOfSeats);
            int result = cmd.ExecuteNonQuery();

            conn.Close();
        }
Exemple #2
0
        public string UpdateABus(UpdateABus bus)
        {
            ABCTourDB_BasharJebryEntities context = new ABCTourDB_BasharJebryEntities();


            string  msg     = string.Empty;
            BusInfo newInfo = new BusInfo();


            try
            {
                var updatedInfo = context.BusInfoes.Find(bus.BusId);
                updatedInfo.Make      = bus.Make;
                updatedInfo.Model     = bus.Model;
                updatedInfo.NoOfSeats = bus.NoOfSeats;
                context.SaveChanges();
                msg = "Record Updated!!";
                SqlConnection conn;
                SqlCommand    cmd;
                conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Resume\copy\copy\copy\copy\FinalExamProjectAndScreenShots-BasharJebry\FinalExam\FinalExam-BasharJebry\ABCTourDB_BasharJebry.mdf;Integrated Security=True");
                conn.Open();
                cmd = new SqlCommand("Update BusInfo set Model=@Model, Make=@Make ,NoOfSeats=@NoOfSeats where BusId=@BusId", conn);
                cmd.Parameters.AddWithValue("@BusId", bus.BusId);
                cmd.Parameters.AddWithValue("@Make", bus.Make);
                cmd.Parameters.AddWithValue("@Model", bus.Model);
                cmd.Parameters.AddWithValue("@NoOfSeats", bus.NoOfSeats);
                int result = cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                msg = ex.Message;
                msg = "Data updating failed!!";
                return(msg);
            }
            return(msg);
        }