Ejemplo n.º 1
0
        private void load_dataGridView_student()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                BindingSource bindingsource = new BindingSource();

                List <DBstudent> rec = DBstudent.GetData();
                foreach (DBstudent data in rec)
                {
                    bindingsource.Add(data);
                }

                this.dataGridView_student.Refresh();
                this.dataGridView_student.AutoGenerateColumns = false;
                this.dataGridView_student.DataSource          = bindingsource;
                this.dataGridView_student.ClearSelection();

                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Ejemplo n.º 2
0
        private void buttonS_Click(object sender, EventArgs e)
        {
            enAbleButton();
            if (isAdd)
            {
                DBstudent add = new DBstudent(textBoxF.Text, textBoxL.Text, textBoxM.Text);
                add.Add();

                load_dataGridView_student();

                MessageBox.Show("Added successfuly");
            }
        }
Ejemplo n.º 3
0
        public static List <DBstudent> GetData()
        {
            List <DBstudent> data = new List <DBstudent>();

            MySqlConnection con = DBConnection.ConnectDatabase();

            try
            {
                MySqlCommand    cmd    = new MySqlCommand("SELECT * FROM " + tablename, con);
                MySqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        DBstudent rawData = new DBstudent();
                        rawData.Id         = reader.GetInt32(0);
                        rawData.firstName  = reader.GetString(1);
                        rawData.lastName   = reader.GetString(2);
                        rawData.middleName = reader.GetString(3);

                        data.Add(rawData);
                    }
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(data);
        }