Ejemplo n.º 1
0
        public string updateStudentByID(StudentDTO student)
        {
            try
            {
                MySqlConnection co = MConnect.getConnection();
                co.Open();
                string       query = "update stud set fname=@a1 where sid=@a2";
                MySqlCommand com   = new MySqlCommand(query, co);
                com.Parameters.AddWithValue("@a1", student.fname);
                com.Parameters.AddWithValue("@a2", student.sid);

                System.Console.WriteLine(com.ExecuteNonQuery());
            }
            catch (System.Exception e)
            {
                throw new System.Exception(e.Message);
            }
            finally{
            }
            return("Updated!");
        }
Ejemplo n.º 2
0
        public string InsertStudent(StudentDTO student)
        {
            try
            {
                MySqlConnection co = MConnect.getConnection();
                co.Open();
                string query = "insert into stud values(@a1,@a2,@a3)";

                MySqlCommand com = new MySqlCommand(query, co);
                com.Parameters.AddWithValue("@a1", student.sid);
                com.Parameters.AddWithValue("@a2", student.fname);
                com.Parameters.AddWithValue("@a3", student.dob);
                com.ExecuteNonQuery();
            }
            catch (System.Exception e)
            {
                throw new System.Exception(e.Message);
            }
            finally{
            }
            return("inserted!");
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            StudentDAO studentDAO = new StudentDAO();

            // List<StudentDTO> students = studentDAO.GetStudentByID("1005");
            // foreach (var item in students)
            // {
            //     System.Console.WriteLine(item.fname + " " + item.sid + " " + item.dob);
            // }

            System.Console.WriteLine("Enter student details: sid fname dob");
            StudentDTO student = new StudentDTO();

            student.sid   = Console.ReadLine();
            student.fname = Console.ReadLine();
            student.dob   = Console.ReadLine();

            // System.Console.WriteLine(studentDAO.InsertStudent(student));
            // System.Console.WriteLine(studentDAO.InsertStudentUsingProcedure(student));
            // System.Console.WriteLine(studentDAO.deleteStudentByID("1010"));
            System.Console.WriteLine(studentDAO.updateStudentByID(student));
        }
Ejemplo n.º 4
0
        public string InsertStudentUsingProcedure(StudentDTO student)
        {
            try
            {
                MySqlConnection co = MConnect.getConnection();
                co.Open();
                string query = "p2";

                MySqlCommand com = new MySqlCommand(query, co);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("a1", student.sid);
                com.Parameters.AddWithValue("a2", student.fname);
                com.Parameters.AddWithValue("a3", student.dob);
                com.ExecuteNonQuery();
            }
            catch (System.Exception e)
            {
                throw new System.Exception(e.Message);
            }
            finally{
            }
            return("inserted!");
        }