示例#1
0
文件: Shippers.cs 项目: ihugya1/BAIST
        public bool AddShipper(Shipper newShipper, string user, string password)
        {
            bool Success = true;

            Console.WriteLine("Execute Enroll Student ");

            //establish a connection
            //SqlConnection ihugya1 = new SqlConnection();
            SqlConnection BAIS3150;         //declararation

            BAIS3150 = new SqlConnection(); //instantiation
            BAIS3150.ConnectionString = @$ "Persist Security Info=False;Database=Northwind;User ID={user};Password={password};server=dev1.baist.ca;";
            BAIS3150.Open();
            SqlCommand AddShipperCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            AddShipperCommand.Connection  = BAIS3150;
            AddShipperCommand.CommandType = CommandType.StoredProcedure;
            AddShipperCommand.CommandText = "ihugya1.AddShipper";
            SqlParameter AddShipperParameter;

            AddShipperParameter = new SqlParameter //object initialization
            {
                ParameterName = "@ShipperID",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newShipper.ShipperID
            };
            AddShipperCommand.Parameters.Add(AddShipperParameter);
            AddShipperParameter = new SqlParameter
            {
                ParameterName = "@CompanyName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newShipper.CompanyName
            };
            AddShipperCommand.Parameters.Add(AddShipperParameter);
            AddShipperParameter = new SqlParameter
            {
                ParameterName = "@PhoneNumber",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newShipper.Phone
            };
            AddShipperCommand.Parameters.Add(AddShipperParameter);

            try
            {
                AddShipperCommand.ExecuteNonQuery();//not getting a result back
            }
            catch (Exception e)
            {
                Success = false;
                Console.WriteLine(e);
                return(Success);
            }
            Console.WriteLine("Success: Added Student");
            Success = true;
            BAIS3150.Close();
            return(Success);
        }
示例#2
0
        static void ExecuteDeleteStudent(string user, string password)
        {
            Console.WriteLine("Execute Delete Student ");
            SqlConnection BAIS3150;         //declararation

            BAIS3150 = new SqlConnection(); //instantiation
            BAIS3150.ConnectionString = @$ "Persist Security Info=False;Database={user};User ID={user};Password={password};server=dev1.baist.ca;";
            BAIS3150.Open();
            SqlCommand DeleteStudentCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            DeleteStudentCommand.Connection  = BAIS3150;
            DeleteStudentCommand.CommandType = CommandType.StoredProcedure;
            DeleteStudentCommand.CommandText = "StudentDelete";
            SqlParameter DeleteStudentParameter;

            DeleteStudentParameter = new SqlParameter //object initialization
            {
                ParameterName = "@StudentID",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = "123456"
            };
            DeleteStudentCommand.Parameters.Add(DeleteStudentParameter);
            DeleteStudentCommand.ExecuteNonQuery();//not getting a result back
            Console.WriteLine("Success: Delete Student");
            BAIS3150.Close();
        }//eoExecuteDeleteStudent
示例#3
0
        public bool AddProgram(string programCode, string description)
        {
            Console.WriteLine("Execute Add program");
            string user,
                   password;

            Console.Write("Please enter DB Name : ");
            user = Console.ReadLine();
            Console.Write("Please enter DB Password : "******"Persist Security Info=False;Database={user};User ID={user};Password={password};server=dev1.baist.ca;";
            BAIS3150.Open();
            SqlCommand ASampleCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            ASampleCommand.Connection  = BAIS3150;
            ASampleCommand.CommandType = CommandType.StoredProcedure;
            ASampleCommand.CommandText = "AddProgram";
            SqlParameter ASampleCommandParameter;

            ASampleCommandParameter = new SqlParameter //object initialization
            {
                ParameterName = "@ProgramCode",
                SqlDbType     = SqlDbType.VarChar,
                //this is a input parameter -> no need to input (10) or "size"
                Direction = ParameterDirection.Input,
                SqlValue  = programCode
            };
            ASampleCommand.Parameters.Add(ASampleCommandParameter);
            ASampleCommandParameter = new SqlParameter
            {
                ParameterName = "@Description",
                SqlDbType     = SqlDbType.VarChar,
                //this is a input parameter -> no need to input (10) or "size"
                Direction = ParameterDirection.Input,
                SqlValue  = description
            };
            ASampleCommand.Parameters.Add(ASampleCommandParameter);
            try
            {
                ASampleCommand.ExecuteNonQuery(); //not getting a result back
            }
            catch (Exception e)
            {
                success = false;
                Console.WriteLine($"Failure: {e}");
                return(success);
            }
            Console.WriteLine("Success: ExecuteNonQuery");
            BAIS3150.Close();
            return(success);
        }
示例#4
0
文件: Programs.cs 项目: ihugya1/BAIST
        public bool AddProgram(string programCode, string description)
        {
            bool success = true;

            ConfigurationBuilder DatabaseUsersBuilder = new ConfigurationBuilder();

            DatabaseUsersBuilder.SetBasePath(Directory.GetCurrentDirectory());
            DatabaseUsersBuilder.AddJsonFile("appsettings.json");
            IConfiguration DatabaseUsersConfiguration = DatabaseUsersBuilder.Build();
            SqlConnection  BAIS3150 = new SqlConnection();

            BAIS3150.ConnectionString = DatabaseUsersConfiguration.GetConnectionString("BAIS3150");
            BAIS3150.Open();
            SqlCommand ASampleCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            ASampleCommand.Connection  = BAIS3150;
            ASampleCommand.CommandType = CommandType.StoredProcedure;
            ASampleCommand.CommandText = "AddProgram";
            SqlParameter ASampleCommandParameter;

            ASampleCommandParameter = new SqlParameter //object initialization
            {
                ParameterName = "@ProgramCode",
                SqlDbType     = SqlDbType.VarChar,
                //this is a input parameter -> no need to input (10) or "size"
                Direction = ParameterDirection.Input,
                SqlValue  = programCode
            };
            ASampleCommand.Parameters.Add(ASampleCommandParameter);
            ASampleCommandParameter = new SqlParameter
            {
                ParameterName = "@Description",
                SqlDbType     = SqlDbType.VarChar,
                //this is a input parameter -> no need to input (10) or "size"
                Direction = ParameterDirection.Input,
                SqlValue  = description
            };
            ASampleCommand.Parameters.Add(ASampleCommandParameter);
            try
            {
                ASampleCommand.ExecuteNonQuery(); //not getting a result back
            }
            catch (Exception e)
            {
                success = false;
                Console.WriteLine($"Failure: {e}");
                return(success);
            }
            Console.WriteLine("Success: ExecuteNonQuery");
            BAIS3150.Close();
            return(success);
        }
示例#5
0
文件: Students.cs 项目: ihugya1/BAIST
        public bool DeleteStudent(string studentID)
        {
            bool   success = true;
            string user, password;

            Console.Write("Please enter DB Name : ");
            user = Console.ReadLine();
            Console.Write("Please enter DB Password : "******"Persist Security Info=False;Database={user};User ID={user};Password={password};server=dev1.baist.ca;";
            BAIS3150.Open();
            SqlCommand DeleteStudentCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            DeleteStudentCommand.Connection  = BAIS3150;
            DeleteStudentCommand.CommandType = CommandType.StoredProcedure;
            DeleteStudentCommand.CommandText = "StudentDelete";
            SqlParameter DeleteStudentParameter;

            DeleteStudentParameter = new SqlParameter //object initialization
            {
                ParameterName = "@StudentID",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = "123456789"
            };
            DeleteStudentCommand.Parameters.Add(DeleteStudentParameter);
            try
            {
                DeleteStudentCommand.ExecuteNonQuery();//not getting a result back
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                success = false;
                return(success);

                throw;
            }
            Console.WriteLine("Success: Delete Student");
            BAIS3150.Close();
            return(success);
        }
示例#6
0
        public bool DeleteItem(string itemCode)
        {
            bool success = true;

            ConfigurationBuilder DatabaseUsersBuilder = new ConfigurationBuilder();

            DatabaseUsersBuilder.SetBasePath(Directory.GetCurrentDirectory());
            DatabaseUsersBuilder.AddJsonFile("appsettings.json");
            IConfiguration DatabaseUsersConfiguration = DatabaseUsersBuilder.Build();
            SqlConnection  BAIS3150 = new SqlConnection();

            BAIS3150.ConnectionString = DatabaseUsersConfiguration.GetConnectionString("BAIS3150");
            BAIS3150.Open();
            SqlCommand DeleteItemCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            DeleteItemCommand.Connection  = BAIS3150;
            DeleteItemCommand.CommandType = CommandType.StoredProcedure;
            DeleteItemCommand.CommandText = "DeleteItem";
            SqlParameter DeleteItemParameter;

            DeleteItemParameter = new SqlParameter //object initialization
            {
                ParameterName = "@ItemCode",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = itemCode
            };
            DeleteItemCommand.Parameters.Add(DeleteItemParameter);
            try
            {
                DeleteItemCommand.ExecuteNonQuery();//not getting a result back
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                success = false;
                return(success);

                throw;
            }
            Console.WriteLine("Success: Delete Item");
            BAIS3150.Close();
            return(success);
        }
示例#7
0
        static void ExecuteUpdateStudent(string user, string password)
        {
            Console.WriteLine("Execute Add Student ");
            //establish a connection
            //SqlConnection ihugya1 = new SqlConnection();
            SqlConnection BAIS3150;         //declararation

            BAIS3150 = new SqlConnection(); //instantiation
            BAIS3150.ConnectionString = @$ "Persist Security Info=False;Database={user};User ID={user};Password={password};server=dev1.baist.ca;";
            BAIS3150.Open();
            SqlCommand UpdateStudentCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            UpdateStudentCommand.Connection  = BAIS3150;
            UpdateStudentCommand.CommandType = CommandType.StoredProcedure;
            UpdateStudentCommand.CommandText = "UpdateStudent";
            SqlParameter UpdateStudentParameter;

            UpdateStudentParameter = new SqlParameter //object initialization
            {
                ParameterName = "@StudentID",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = "123456788"
            };
            UpdateStudentCommand.Parameters.Add(UpdateStudentParameter);
            UpdateStudentParameter = new SqlParameter
            {
                ParameterName = "@FirstName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = "Larry"
            };
            UpdateStudentCommand.Parameters.Add(UpdateStudentParameter);
            UpdateStudentParameter = new SqlParameter
            {
                ParameterName = "@LastName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = "larLarLar"
            };
            UpdateStudentCommand.Parameters.Add(UpdateStudentParameter);
            UpdateStudentParameter = new SqlParameter
            {
                ParameterName = "@Email",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = "*****@*****.**"
            };
            UpdateStudentCommand.Parameters.Add(UpdateStudentParameter);
            UpdateStudentParameter = new SqlParameter
            {
                ParameterName = "@ProgramCode",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = "PHOT"
            };
            UpdateStudentCommand.Parameters.Add(UpdateStudentParameter);
            UpdateStudentCommand.ExecuteNonQuery();//not getting a result back
            Console.WriteLine("Success: Updated Student");
            BAIS3150.Close();
        }
示例#8
0
        static void ExecuteAddStudent(string user, string password)
        {
            Console.WriteLine("Execute Add Student ");
            string studentID, firstName, lastName, email, programCode;

            Console.Write("Please enter Student ID : ");
            studentID = Console.ReadLine();
            Console.Write("Please enter student First Name : ");
            firstName = Console.ReadLine();
            Console.Write("Please enter student Last Name : ");
            lastName = Console.ReadLine();
            Console.Write("Please enter student Email : ");
            email = Console.ReadLine();
            Console.Write("Please enter student Program Code : ");
            programCode = Console.ReadLine();
            //establish a connection
            //SqlConnection ihugya1 = new SqlConnection();
            SqlConnection BAIS3150;         //declararation

            BAIS3150 = new SqlConnection(); //instantiation
            BAIS3150.ConnectionString = @$ "Persist Security Info=False;Database={user};User ID={user};Password={password};server=dev1.baist.ca;";
            BAIS3150.Open();
            SqlCommand AddStudentCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            AddStudentCommand.Connection  = BAIS3150;
            AddStudentCommand.CommandType = CommandType.StoredProcedure;
            AddStudentCommand.CommandText = "AddStudent";
            SqlParameter AddStudentParameter;

            AddStudentParameter = new SqlParameter //object initialization
            {
                ParameterName = "@StudentID",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = studentID
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@FirstName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = firstName
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@LastName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = lastName
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@Email",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = email
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@ProgramCode",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = programCode
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentCommand.ExecuteNonQuery();//not getting a result back
            Console.WriteLine("Success: Added Student");
            BAIS3150.Close();
        }
示例#9
0
        public bool UpdateItem(Item newItem)
        {
            bool success = true;
            ConfigurationBuilder DatabaseUsersBuilder = new ConfigurationBuilder();

            DatabaseUsersBuilder.SetBasePath(Directory.GetCurrentDirectory());
            DatabaseUsersBuilder.AddJsonFile("appsettings.json");
            IConfiguration DatabaseUsersConfiguration = DatabaseUsersBuilder.Build();
            SqlConnection  BAIS3150 = new SqlConnection();

            BAIS3150.ConnectionString = DatabaseUsersConfiguration.GetConnectionString("BAIS3150");
            BAIS3150.Open();
            SqlCommand UpdateItemCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            UpdateItemCommand.Connection  = BAIS3150;
            UpdateItemCommand.CommandType = CommandType.StoredProcedure;
            UpdateItemCommand.CommandText = "UpdateItem";
            SqlParameter UpdateItemParameter;

            UpdateItemParameter = new SqlParameter //object initialization
            {
                ParameterName = "@ItemCode",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newItem.ItemCode
            };
            UpdateItemCommand.Parameters.Add(UpdateItemParameter);
            UpdateItemParameter = new SqlParameter
            {
                ParameterName = "@ItemDescription",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newItem.ItemDescription
            };
            UpdateItemCommand.Parameters.Add(UpdateItemParameter);
            UpdateItemParameter = new SqlParameter
            {
                ParameterName = "@UnitPrice",
                SqlDbType     = SqlDbType.SmallMoney,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newItem.UnitPrice
            };
            UpdateItemCommand.Parameters.Add(UpdateItemParameter);
            UpdateItemParameter = new SqlParameter
            {
                ParameterName = "@QuantityOnHand",
                SqlDbType     = SqlDbType.Int,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newItem.QuantityOnHand
            };
            UpdateItemCommand.Parameters.Add(UpdateItemParameter);

            try
            {
                UpdateItemCommand.ExecuteNonQuery();//not getting a result back
            }
            catch (Exception e)
            {
                success = false;
                Console.WriteLine(e);
                return(success);
            }
            Console.WriteLine("Success: Added Item");
            success = true;
            BAIS3150.Close();
            return(success);
        }
示例#10
0
        public bool UpdateCustomer(Customer newCustomer) //parameters, camel casing
        {
            bool Success = true;

            ConfigurationBuilder DatabaseUsersBuilder = new ConfigurationBuilder();

            DatabaseUsersBuilder.SetBasePath(Directory.GetCurrentDirectory());
            DatabaseUsersBuilder.AddJsonFile("appsettings.json");
            IConfiguration DatabaseUsersConfiguration = DatabaseUsersBuilder.Build();
            SqlConnection  BAIS3150 = new SqlConnection();

            BAIS3150.ConnectionString = DatabaseUsersConfiguration.GetConnectionString("BAIS3150");
            BAIS3150.Open();
            SqlCommand AddCustomerCommand = new SqlCommand();

            AddCustomerCommand.Connection  = BAIS3150;
            AddCustomerCommand.CommandType = CommandType.StoredProcedure;
            AddCustomerCommand.CommandText = "UpdateCustomer";
            SqlParameter AddCustomerParameter;

            AddCustomerParameter = new SqlParameter //object initialization
            {
                ParameterName = "@CustomerID",
                SqlDbType     = SqlDbType.Int,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newCustomer.CustomerID
            };
            AddCustomerCommand.Parameters.Add(AddCustomerParameter);
            AddCustomerParameter = new SqlParameter
            {
                ParameterName = "@CustomerName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newCustomer.CustomerName
            };
            AddCustomerCommand.Parameters.Add(AddCustomerParameter);
            AddCustomerParameter = new SqlParameter
            {
                ParameterName = "@Address",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newCustomer.Address
            };
            AddCustomerCommand.Parameters.Add(AddCustomerParameter);
            AddCustomerParameter = new SqlParameter
            {
                ParameterName = "@Province",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newCustomer.Province
            };
            AddCustomerCommand.Parameters.Add(AddCustomerParameter);
            AddCustomerParameter = new SqlParameter
            {
                ParameterName = "@City",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newCustomer.City
            };
            AddCustomerCommand.Parameters.Add(AddCustomerParameter);
            AddCustomerParameter = new SqlParameter
            {
                ParameterName = "@PostalCode",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = newCustomer.PostalCode
            };
            AddCustomerCommand.Parameters.Add(AddCustomerParameter);



            try
            {
                AddCustomerCommand.ExecuteNonQuery();//not getting a result back
            }
            catch (Exception e)
            {
                Success = false;
                Console.WriteLine(e);
                return(Success);
            }
            Console.WriteLine("Success: Updated Customer");
            Success = true;
            BAIS3150.Close();
            return(Success);
        }
示例#11
0
文件: Students.cs 项目: ihugya1/BAIST
        public bool UpdateStudent(Student student)
        {
            bool   success  = true;
            string user     = "******";
            string password = "******";
            //establish a connection
            //SqlConnection ihugya1 = new SqlConnection();
            SqlConnection BAIS3150;         //declararation

            BAIS3150 = new SqlConnection(); //instantiation
            BAIS3150.ConnectionString = @$ "Persist Security Info=False;Database={user};User ID={user};Password={password};server=dev1.baist.ca;";
            BAIS3150.Open();
            SqlCommand UpdateStudentCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            UpdateStudentCommand.Connection  = BAIS3150;
            UpdateStudentCommand.CommandType = CommandType.StoredProcedure;
            UpdateStudentCommand.CommandText = "UpdateStudent";
            SqlParameter UpdateStudentParameter;

            UpdateStudentParameter = new SqlParameter //object initialization
            {
                ParameterName = "@StudentID",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = student.StudentID
            };
            UpdateStudentCommand.Parameters.Add(UpdateStudentParameter);
            UpdateStudentParameter = new SqlParameter
            {
                ParameterName = "@FirstName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = student.FirstName
            };
            UpdateStudentCommand.Parameters.Add(UpdateStudentParameter);
            UpdateStudentParameter = new SqlParameter
            {
                ParameterName = "@LastName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = student.LastName
            };
            UpdateStudentCommand.Parameters.Add(UpdateStudentParameter);
            UpdateStudentParameter = new SqlParameter
            {
                ParameterName = "@Email",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = student.Email
            };


            UpdateStudentCommand.Parameters.Add(UpdateStudentParameter);
            try
            {
                UpdateStudentCommand.ExecuteNonQuery();//not getting a result back
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                success = false;
                return(success);

                throw;
            }
            Console.WriteLine("Success: Updated Student");
            BAIS3150.Close();
            return(success);
        }
示例#12
0
文件: Students.cs 项目: ihugya1/BAIST
        public bool AddStudent(Student acceptedStudent, string programCode) //parameters, camel casing
        {
            bool Success = true;

            ConfigurationBuilder DatabaseUsersBuilder = new ConfigurationBuilder();

            DatabaseUsersBuilder.SetBasePath(Directory.GetCurrentDirectory());
            DatabaseUsersBuilder.AddJsonFile("appsettings.json");
            IConfiguration DatabaseUsersConfiguration = DatabaseUsersBuilder.Build();
            SqlConnection  BAIS3150 = new SqlConnection();

            BAIS3150.ConnectionString = DatabaseUsersConfiguration.GetConnectionString("BAIS3150");
            BAIS3150.Open();
            SqlCommand AddStudentCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            AddStudentCommand.Connection  = BAIS3150;
            AddStudentCommand.CommandType = CommandType.StoredProcedure;
            AddStudentCommand.CommandText = "AddStudent";
            SqlParameter AddStudentParameter;

            AddStudentParameter = new SqlParameter //object initialization
            {
                ParameterName = "@StudentID",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = acceptedStudent.StudentID
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@FirstName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = acceptedStudent.FirstName
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@LastName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = acceptedStudent.LastName
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@Email",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = acceptedStudent.Email
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@ProgramCode",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = programCode
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            try
            {
                AddStudentCommand.ExecuteNonQuery();//not getting a result back
            }
            catch (Exception e)
            {
                Success = false;
                Console.WriteLine(e);
                return(Success);
            }
            Console.WriteLine("Success: Added Student");
            Success = true;
            BAIS3150.Close();
            return(Success);
        }
示例#13
0
文件: Students.cs 项目: ihugya1/BAIST
        public bool AddStudent(Student acceptedStudent, string programCode) //parameters, camel casing
        {
            bool Success = true;

            Console.WriteLine("Execute Enroll Student ");
            string user, password;

            Console.Write("Please enter DB Name : ");
            user = Console.ReadLine();
            Console.Write("Please enter DB Password : "******"Persist Security Info=False;Database={user};User ID={user};Password={password};server=dev1.baist.ca;";
            BAIS3150.Open();
            SqlCommand AddStudentCommand = new SqlCommand(); // this is declaration and instantiation wooowwwww very cool

            AddStudentCommand.Connection  = BAIS3150;
            AddStudentCommand.CommandType = CommandType.StoredProcedure;
            AddStudentCommand.CommandText = "AddStudent";
            SqlParameter AddStudentParameter;

            AddStudentParameter = new SqlParameter //object initialization
            {
                ParameterName = "@StudentID",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = acceptedStudent.StudentID
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@FirstName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = acceptedStudent.FirstName
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@LastName",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = acceptedStudent.LastName
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@Email",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = acceptedStudent.Email
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            AddStudentParameter = new SqlParameter
            {
                ParameterName = "@ProgramCode",
                SqlDbType     = SqlDbType.VarChar,//this is a input parameter -> no need to input (10) or "size"
                Direction     = ParameterDirection.Input,
                SqlValue      = programCode
            };
            AddStudentCommand.Parameters.Add(AddStudentParameter);
            try
            {
                AddStudentCommand.ExecuteNonQuery();//not getting a result back
            }
            catch (Exception e)
            {
                Success = false;
                Console.WriteLine(e);
                return(Success);
            }
            Console.WriteLine("Success: Added Student");
            Success = true;
            BAIS3150.Close();
            return(Success);
        }