예제 #1
0
파일: Class2.cs 프로젝트: Jebry/ABCTOUR
        public void insert(InsertABus 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("Insert into BusInfo values(@BusId, @Make, @Model,@NoOfSeat)", conn);
            cmd.Parameters.AddWithValue("@BusId", bus.BusId);
            cmd.Parameters.AddWithValue("@Make", bus.Make);
            cmd.Parameters.AddWithValue("@Model", bus.Model);
            cmd.Parameters.AddWithValue("@NoOfSeat", bus.NoOfSeats);
            int result = cmd.ExecuteNonQuery();

            conn.Close();
        }
예제 #2
0
        public string InsertABus(InsertABus bus)
        {
            ABCTourDB_BasharJebryEntities context = new ABCTourDB_BasharJebryEntities();

            string msg = string.Empty;

            BusInfo newInfo = new BusInfo()
            {
                BusId     = bus.BusId,
                Make      = bus.Make,
                Model     = bus.Model,
                NoOfSeats = bus.NoOfSeats
            };

            try
            {
                context.BusInfoes.Add(newInfo);
                context.SaveChanges();
                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("Insert into BusInfo values(@BusId, @Make, @Model,@NoOfSeat)", conn);
                cmd.Parameters.AddWithValue("@BusId", bus.BusId);
                cmd.Parameters.AddWithValue("@Make", bus.Make);
                cmd.Parameters.AddWithValue("@Model", bus.Model);
                cmd.Parameters.AddWithValue("@NoOfSeat", bus.NoOfSeats);
                int result = cmd.ExecuteNonQuery();
                conn.Close();
                msg = "Record inserted";
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                msg = ex.Message;
                msg = "Record NOT inserted";
            }
            return(msg);
        }