0% found this document useful (0 votes)
530 views

Insert, Update Delete C# Dan Mysql PDF

The document provides steps to insert, update, and delete data from a MySQL database using C#. It includes creating a database table, designing a form interface in C# with textboxes and buttons, adding code to a class to connect to the database and execute queries, and adding code to button click events to perform insert, update, and delete operations. The document also provides screenshots of the database table and form interface.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
530 views

Insert, Update Delete C# Dan Mysql PDF

The document provides steps to insert, update, and delete data from a MySQL database using C#. It includes creating a database table, designing a form interface in C# with textboxes and buttons, adding code to a class to connect to the database and execute queries, and adding code to button click events to perform insert, update, and delete operations. The document also provides screenshots of the database table and form interface.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

insert,update delete c# dan Mysql

12

1. Kita Akan Membuat Tampilan Form Sebagai Berikut : silakan disain seperti tampilan di bawah ini.

2. Sebelumnya Buat Database seperti gambar di bawah :

3. Jangan Lupa lakukan Pengaturan seperti gambar di bawah: Caranya klik kanan References lalu ikuti gambar : Page 2

4. Untuk Propertinya terserah anda pada tutorial berukut ini mengatur property sebagai berikut : TeaxtBox1 Name :nam TeaxtBox12 Name : telp TeaxtBox13 Name : alamat TextBox4 Button1 Name : id Button2 Button3 Text : Alamat

Text : insert Text : Update

5. Buat Class Baru lalu isikan code berikut :

using using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.Windows.Forms; MySql.Data.MySqlClient;

namespace insert_ipdate_delete { class ukuran { MySqlConnection conn = new MySqlConnection("server = localhost;uid=root;pwd =;Database=vb;"); public void QUERY(String sql) {

Page 3

conn.Open(); try { MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery();

} catch (Exception ex) { MessageBox.Show(ex.Message, "Error??"); } finally { conn.Close(); }

} } }

6. Tambahkan koding pada masing-masing Button seperti Di Bawah :

using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

namespace insert_ipdate_delete { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

ukuran uk;

private void button2_Click(object sender, EventArgs e) { uk = new ukuran();

Page 4

uk.QUERY("update telp set nama='"+this.nama.Text+"',telp='"+this.telp.Text+"',alamat='"+this.alamat.Text+"' where id='"+this.id.Text+"'"); MessageBox.Show("Update Sukses"); } private void button1_Click(object sender, EventArgs e) { uk = new ukuran(); uk.QUERY("insert into telp(id,nama,telp,alamat)values('"+this.id.Text+"','"+this.nama.Text+"','"+this.telp.T ext+"','"+this.alamat.Text+"')"); MessageBox.Show("Insert Data Berhasil"); } private void button3_Click(object sender, EventArgs e) { uk = new ukuran(); uk.QUERY("delete from telp where id ='"+this.id.Text+"'"); MessageBox.Show("Delete Sukses"); }

Page 5

7. Silakan Runing .jika berhasil maka akan seperti gambar di bawah :

Jika Berhasil Maka Di Database akan terlihat data yang di import :

Page 6

Oke demikian duluyah,dari ane,apabila ada kekurangan mohon maaf,kita sama-sama belajar,,,,,wek.wek..supaya lebh kenal lagi berikut biodata penulis,,,

Perkenalkan nama ane Muhamad Ali,panggil saja Ali atau Al,nah sekarang ini ane masih kuliah di salah satu sekolah Tinggi suwasta,pada semester 4.ane uga dulu pernah sekolah di SMA jurusan IPA,,lulus kemudian melanjutkan kuliah di jurusan Tehnik Komputer dan Informatika di salah satu perguruan tinggi suasta. Yah demikian singkatdeh perkenalan dari ane, teriakasih telah mengunjungi website ane di www.muhamadali.besaba.comatau www.ceritaalialdefinu.wordpress.com,apa bila banyak kekurangan ane mohon maff,,, semoga kita menjadi orang yang bermanfaat untuk orang lain,,amin,,,

Page 7

You might also like