Public Class frmanggota
Dim connsql As SqlClient.SqlConnection
Dim dataadapteranggota As SqlClient.SqlDataAdapter
Dim tabelanggota As New DataTable
Dim cmdtabelanggota As SqlClient.SqlCommandBuilder
Dim strkoneksi As String
Dim recordanggota As DataRow
Dim posisirecord As Integer
Sub tampilkandata()
dgView.DataSource = tabelanggota
If tabelanggota.Rows.Count <> 0 Then
txtnoanggota.Text = recordanggota("noanggota")
txtnama.Text = recordanggota("namaanggota")
txtalamat.Text = recordanggota("alamat")
cmbkelamin.Text = recordanggota("jeniskelamin")
Else
MsgBox("Data Kosong", MsgBoxStyle.Information, "Informasi")
End If
End Sub
Private Sub frmanggota_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'tutupkoneksi()
connsql.Close()
connsql.Dispose()
End Sub
Private Sub frmanggota_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
strkoneksi = "Data Source=JAHIR-19D23153D\SQLEXPRESS;Initial Catalog=dbsimpin;Integrated Security=True"
'bukakoneksi()
connsql = New SqlClient.SqlConnection(strkoneksi)
connsql.Open()
dataadapteranggota = New SqlClient.SqlDataAdapter("select noanggota,namaanggota,alamat," _
& "jeniskelamin from tbanggota", connsql)
dataadapteranggota.Fill(tabelanggota)
cmdtabelanggota = New SqlClient.SqlCommandBuilder(dataadapteranggota)
recordanggota = tabelanggota.Rows(0)
tampilkandata()
End Sub
Private Sub cmdtambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdtambah.Click
frmtambahdata.ShowDialog()
dataadapteranggota.Fill(tabelanggota)
End Sub
Private Sub cmdhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdhapus.Click
tabelanggota.Rows(posisirecord).Delete()
dataadapteranggota.Update(tabelanggota)
posisirecord = 0
tampilkandata()
End Sub
Private Sub smdsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles smdsimpan.Click
recordanggota("noanggota") = txtnoanggota.Text
recordanggota("namaanggota") = txtnama.Text
recordanggota("alamat") = txtalamat.Text
recordanggota("jeniskelamin") = cmbkelamin.Text
dataadapteranggota.Update(tabelanggota)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If tabelanggota.Rows.Count <> 0 Then
posisirecord = 0
recordanggota = tabelanggota.Rows(posisirecord)
tampilkandata()
Else
MsgBox("Data Kosong", MsgBoxStyle.Information, "Informasi")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If tabelanggota.Rows.Count > 0 Then
posisirecord = posisirecord - 1
recordanggota = tabelanggota.Rows(posisirecord)
tampilkandata()
Else
MsgBox("Data Kosong", MsgBoxStyle.Information, "Informasi")
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If posisirecord < (tabelanggota.Rows.Count - 1) Then
posisirecord = posisirecord + 1
recordanggota = tabelanggota.Rows(posisirecord)
tampilkandata()
Else
MsgBox("Data Kosong", MsgBoxStyle.Information, "Informasi")
End If
End Sub
End Class