1 / 9

Button Save Delete Edit

Button Save Delete Edit. Sasa Ani Arnomo , S.Kom ., M.S.I. Buat databasenya lewat acces : Nama database => Database Mahasiswa Nama tabel => t blmahasiswa Kemudian rancang Form berikut :::::::. Masukkan tambahan header dipaling atas : Using System.Data.OleDb ;

yon
Télécharger la présentation

Button Save Delete Edit

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Button Save Delete Edit SasaAniArnomo, S.Kom., M.S.I

  2. Buatdatabasenyalewatacces: Nama database => Database Mahasiswa Namatabel => tblmahasiswa Kemudianrancang Form berikut:::::::

  3. Masukkantambahan header dipalingatas: Using System.Data.OleDb; ================================== Tandamerah: alamatpenyimpanan database Ditulisdiataspublic Form1() ================================== string koneksi = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/c#/Database Mahasiswa/Database Mahasiswa/Database Mahasiswa.accdb";

  4. Untukmenampilkan database padaDataGridView, bisadilakukandengan 2 cara, yaitu : 1. Cara langsung Padadatagridview, kliktandasegitiga yang adapadapojokkananatasdatagridview. Lalupada Chose Data Source, pilih other data source, project data source, Nama database access, namatabel. 2. Menggunakansyntak Double klikpada form, lalumasukansyntakberikut private void Form1_Load(object sender, EventArgs e)  {             string sql = "SELECT * FROM tblmahasiswa";OleDbConnection con = new OleDbConnection(koneksi);con.Open();OleDbDataAdapter da = new OleDbDataAdapter(sql, con);DataSet ds = new DataSet();da.Fill(ds, "tblmahasiswa");con.Close();            dataGridView1.DataSource = ds.Tables["tblmahasiswa"].DefaultView;       }

  5. Kemudian double klikpadaTombolSimpandanisiSyntakseperti di bawahini private void button1_Click(object sender, EventArgs e)  {                 try                {                    string sql = string.Format("insert into tblMahasiswa (NRP,Nama,Kelas) VALUES                    ('{0}','{1}','{2}')",  textBox1.Text, textBox2.Text, textBox3.Text); OleDbConnection conn = new OleDbConnection(koneksi);conn.Open();OleDbCommandcmd = new OleDbCommand(sql, conn);cmd.ExecuteNonQuery();conn.Close();MessageBox.Show("Data SudahDisimpan");                 }                catch (OleDbExceptionsalah)                {MessageBox.Show(salah.ToString());                }}

  6. TombolHapus private void button2_Click(object sender, EventArgs e)  {            try            {                string sql = string.Format("delete*from tblmahasiswa where nrp='" + textBox1.Text+ "'");OleDbConnection conn = new OleDbConnection(koneksi);conn.Open();OleDbCommandcmd = new OleDbCommand(sql, conn);cmd.ExecuteNonQuery();conn.Close();MessageBox.Show("Data TelahDihapus");            }            catch (OleDbExceptionsalah)            {MessageBox.Show(salah.ToString());            } }

  7. Tombol Update/Edit  private void button3_Click(object sender, EventArgs e)  {                try                 {                    string sql = string.Format("update tblmahasiswa set nama='" + textBox2.Text + "',kelas='" +                     textBox3.Text + "' where nrp='" + textBox1.Text + "'"); OleDbConnection conn = new OleDbConnection(koneksi);conn.Open();OleDbCommandcmd = new OleDbCommand(sql, conn);cmd.ExecuteNonQuery();conn.Close();MessageBox.Show("Perubahan Data SudahDisimpan");                 }                catch (OleDbException ex)                {MessageBox.Show(ex.ToString());                }}

  8. TombolCari private void button4_Click(object sender, EventArgs e) { OleDbDataReaderrdr = null;            try            {                string sql = string.Format("select*from tblmahasiswa where nrp='" +  textBox1.Text + "'");OleDbConnection conn = new OleDbConnection(koneksi);conn.Open();OleDbCommandcmd = new OleDbCommand(sql, conn);rdr=cmd.ExecuteReader();                if(rdr.Read())                {                     textBox2.Text =rdr["nama"].ToString();                     textBox3.Text =rdr["kelas"].ToString();                }                else                {MessageBox.Show("Data TidakDitemukan");                }            }            catch(OleDbException ex)            {MessageBox.Show(ex.ToString());            }}

  9. TombolKeluar  private void button4_Click(object sender, EventArgs e) { this.Close(); }

More Related