Exemplo n.º 1
0
        public static DataTable SearchStudents(Student student)
        {
            if (conndb.State == ConnectionState.Closed)
            {
                conndb = UtilityDB.connectDB();
                cmd    = new SqlCommand();
            }
            cmd.Connection  = conndb;
            cmd.CommandText = string.Format("Select * from Students where FirstName='{0}' or PhoneNumber='{1}'", student.FirstName, student.PhoneNumber);
            SqlDataReader reader = cmd.ExecuteReader();
            DataTable     dt     = new DataTable();

            dt.Load(reader);
            reader.Close();
            cmd.Dispose();
            conndb.Close();
            return(dt);
        }
Exemplo n.º 2
0
 public static bool UpdateStudents(Student student)
 {
     try
     {
         if (conndb.State == ConnectionState.Closed)
         {
             conndb = UtilityDB.connectDB();
             cmd    = new SqlCommand();
         }
         cmd.Connection  = conndb;
         cmd.CommandText = string.Format("update Students set FirstName='{0}' , LastName ='{1}', PhoneNumber = '{2}' where StudentNumber ={3}", student.FirstName, student.LastName, student.PhoneNumber, student.StudentNumber);
         cmd.ExecuteNonQuery();
         conndb.Close();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 3
0
 public static bool AddStudents(Student student)
 {
     try
     {
         if (conndb.State == ConnectionState.Closed)
         {
             conndb = UtilityDB.connectDB();
             cmd    = new SqlCommand();
         }
         cmd.Connection  = conndb;
         cmd.CommandText = string.Format("insert into Students (FirstName,LastName,PhoneNumber) values('{0}','{1}','{2}')", student.FirstName, student.LastName, student.PhoneNumber);
         cmd.ExecuteNonQuery();
         conndb.Close();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        public static DataTable DisplayStudents()
        {
            DataTable datatable = new DataTable();

            try
            {
                if (conndb.State == ConnectionState.Closed)
                {
                    conndb = UtilityDB.connectDB();
                    cmd    = new SqlCommand();
                }
                cmd.Connection  = conndb;
                cmd.CommandText = "select * from Students";
                SqlDataReader reader = cmd.ExecuteReader();
                datatable.Load(reader);
                reader.Close();
                cmd.Dispose();
                conndb.Close();
            }
            catch (Exception)
            {
            }
            return(datatable);
        }