예제 #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (!IdTextBox.Enabled)
         {
             ModelUser user = new ModelUser();
             user.IdWaliMurid   = IdTextBox.Text.ToString();
             user.NamaWaliMurid = NameTextBox.Text.ToString();
             user.Alamat        = FnameTextBox.Text.ToString();
             user.Email         = SemesterTextBox.Text.ToString();
             user.NoTelp        = AgeTextBox.Text.ToString();
             if (daoapps.updateData(user))
             {
                 MessageBox.Show("berhasil update data");
                 IdTextBox.Enabled = true;
             }
             else
             {
                 MessageBox.Show("gagal update data");
             }
             viewDataku();
         }
         else
         {
             ModelUser user = new ModelUser();
             user.IdWaliMurid   = IdTextBox.Text.ToString();
             user.NamaWaliMurid = NameTextBox.Text.ToString();
             user.Alamat        = FnameTextBox.Text.ToString();
             user.Email         = SemesterTextBox.Text.ToString();
             user.NoTelp        = AgeTextBox.Text.ToString();
             if (daoapps.insertBarang(user))
             {
                 MessageBox.Show("Insert data sukses");
                 resetdata();
             }
             else
             {
                 MessageBox.Show("Insert data gagal");
             }
             viewDataku();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #2
0
        public bool insertBarang(ModelUser user)
        {
            bool status = true;

            try
            {
                string          Query      = "insert into student.studentinfo(idStudentInfo,Name,Father_Name,Age,Semester) values('" + user.IdWaliMurid + "','" + user.NamaWaliMurid + "','" + user.Alamat + "','" + user.NoTelp + "','" + user.Email + "');";
                MySqlConnection MyConn2    = new MySqlConnection(MyConnection);
                MySqlCommand    MyCommand2 = new MySqlCommand(Query, MyConn2);
                MySqlDataReader MyReader2;
                MyConn2.Open();
                MyReader2 = MyCommand2.ExecuteReader();     // Here our query will be executed and data saved into the database.
                MyConn2.Close();
            }
            catch (Exception e)
            {
                status = false;
            }
            return(status);
        }
예제 #3
0
        public bool updateData(ModelUser user)
        {
            bool status = true;

            try
            {
                string Query = "update student.studentinfo set idStudentInfo='" + user.IdWaliMurid
                               + "',Name='" + user.NamaWaliMurid + "',Father_Name='" + user.Alamat + "',Age='" + user.NoTelp + "',Semester='" + user.Email + "' where idStudentInfo='" + user.IdWaliMurid + "';";
                MySqlConnection MyConn2    = new MySqlConnection(MyConnection);
                MySqlCommand    MyCommand2 = new MySqlCommand(Query, MyConn2);
                MySqlDataReader MyReader2;
                MyConn2.Open();
                MyReader2 = MyCommand2.ExecuteReader();
                MyConn2.Close();//Connection closed here
            }
            catch (Exception ex)
            {
                status = false;
            }
            return(status);
        }