Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.SqlClient
- Public Class FormUser
- Private Sub FormUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Dim perintah As New SqlCommand
- Dim da As New SqlDataAdapter
- Dim ds As New DataSet
- KoneksiSql = BuatKoneksi()
- KoneksiSql.Open()
- perintah = KoneksiSql.CreateCommand
- perintah.CommandText = "SELECT * FROM TUSER"
- da.SelectCommand = perintah
- da.Fill(ds, "Tuser")
- dgv_user.DataSource = ds
- dgv_user.DataMember = "TUser"
- End Sub
- Private Sub btn_tambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_tambah.Click
- Dim user, nama, pass, status As String
- Dim perintah As New SqlCommand
- Dim da As New SqlDataAdapter
- Dim ds As New DataSet
- user = txt_user.Text
- nama = txt_nama.Text
- pass = txt_pass.Text
- status = cb_status.Text
- KoneksiSql = BuatKoneksi()
- KoneksiSql.Open()
- perintah = KoneksiSql.CreateCommand
- perintah.CommandText = "INSERT INTO Tuser values('" & user & "', '" & nama & "', '" & pass & "' , '" & status & "')"
- perintah.ExecuteNonQuery()
- MsgBox("Data berhasil disimpan", MsgBoxStyle.Information, "*")
- txt_nama.Text = ""
- txt_pass.Text = ""
- txt_user.Text = ""
- cb_status.Text = Nothing
- FormUser_Load(Me, New System.EventArgs)
- End Sub
- Private Sub btn_hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_hapus.Click
- Dim id, jawab As String
- Dim perintah As New SqlCommand
- Dim da As New SqlDataAdapter
- Dim ds As New DataSet
- Dim baris As Integer
- baris = dgv_user.CurrentRow.Index
- id = dgv_user.Item(0, baris).Value
- KoneksiSql = BuatKoneksi()
- KoneksiSql.Open()
- perintah = KoneksiSql.CreateCommand
- jawab = MsgBox("AApakah anda yakin", MsgBoxStyle.YesNo, "Konfirmasi")
- If jawab = vbYes Then
- perintah.CommandText = "DELETE FROM Tuser where IDUser = '" & id & "'"
- perintah.ExecuteNonQuery()
- MsgBox("Data berhasil dihapus")
- FormUser_Load(Me, New System.EventArgs)
- End If
- End Sub
- Private Sub btn_edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_edit.Click
- Dim baris As Integer
- Dim id As String
- Dim perintah As New SqlCommand
- baris = dgv_user.CurrentRow.Index
- id = dgv_user.Item(0, baris).Value
- KoneksiSql = BuatKoneksi()
- KoneksiSql.Open()
- perintah = KoneksiSql.CreateCommand
- perintah.CommandText = "SELECT IDuser,NamaUser,Password,Status FROM Tuser where IDuser = '" & id & "'"
- Dim dr As SqlDataReader
- dr = perintah.ExecuteReader
- dr.Read()
- txt_user.Text = dr(0)
- txt_nama.Text = dr(1)
- txt_pass.Text = dr(2)
- cb_status.Text = dr(3)
- txt_user.Enabled = False
- btn_hapus.Enabled = False
- btn_tambah.Enabled = False
- End Sub
- Private Sub Simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Simpan.Click
- Dim id, nama, job, pass As String
- Dim perintah As New SqlCommand
- id = txt_user.Text
- nama = txt_nama.Text
- pass = txt_pass.Text
- job = cb_status.Text
- KoneksiSql = BuatKoneksi()
- KoneksiSql.Open()
- perintah = KoneksiSql.CreateCommand
- perintah.CommandText = "UPDATE TUser set IDUser = '" & id & "' , NamaUser = '" & nama & "' , Password = '" & pass & "' , Status = '" & job & "' WHERE IDUser = '" & id & "'"
- perintah.ExecuteNonQuery()
- MsgBox("Data Berhasil Diubah")
- txt_user.Text = ""
- txt_nama.Text = ""
- txt_pass.Text = ""
- cb_status.Text = Nothing
- txt_user.Enabled = True
- btn_hapus.Enabled = True
- btn_tambah.Enabled = True
- FormUser_Load(Me, New System.EventArgs)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement