Skrip programnya sebagai berikut :
Imports MySql.Data.MySqlClient
Public Class Pelanggan
Dim kon As New MySqlConnection("server=localhost;User Id=root;database=penjualan")
Dim perintah As New MySqlCommand
Dim data As New MySqlDataAdapter
Dim ds As New DataSet
Sub tampildata()
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "select*from pelanggan"
data.SelectCommand = perintah
ds.Tables.Clear()
data.Fill(ds, "pelanggan")
DataGridView1.DataSource = ds.Tables("pelanggan")
kon.Close()
End Sub
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
tampildata()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "insert into pelanggan (kd_plg,nm_plg,alamat) values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"
perintah.ExecuteNonQuery()
kon.Close()
MsgBox("data sukses tersimpan", MsgBoxStyle.Information, "pesan")
tampildata()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "delete from pelanggan where alamat= '" & TextBox3.Text & "'"
perintah.ExecuteNonQuery()
kon.Close()
MsgBox("data telah dihapus", MsgBoxStyle.Information, "informasi")
tampildata()
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim i As Integer
i = DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(i)
TextBox1.Text = .Cells(0).Value
TextBox2.Text = .Cells(1).Value
TextBox3.Text = .Cells(2).Value
End With
End Sub
End Clas
kalau ada yang kurang jelas silahkan ditanyakan..
sumber: materi kuliah
0 komentar:
Terima kasih sudah memberi komentar,
komentar anda sangat berguna untuk menjadikan blog ane lebih baik lagi..
jangan lupa berkunjung kembali..