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

Kode Data2

Uploaded by

Bang Bang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Kode Data2

Uploaded by

Bang Bang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

C:\Users\Lenovo7\Documents\Project\002\002\Sambung.

vb 1
1 Imports System.Data.SqlClient
2 Imports System.Windows.Forms.VisualStyles.VisualStyleElement
3
4 Public Class Sambung
5 Dim da As SqlDataAdapter
6 Dim ds As DataSet
7 Private Sub ButtonInsert_Click(sender As Object, e As EventArgs)
Handles ButtonInsert.Click
8 ButtonInsert.Enabled = False
9 ButtonUpdate.Enabled = False
10 ButtonDelete.Enabled = False
11 ButtonSave.Enabled = True
12 ButtonCancel.Enabled = True
13 TextBoxUsername.Enabled = True
14 TextBoxPassword.Enabled = True
15 TextBoxID.Enabled = True
16 ComboBoxJob.Enabled = True
17 TextBoxMode.Text = "Insert"
18 TextBoxID.Clear()
19 TextBoxUsername.Clear()
20 TextBoxPassword.Clear()
21 ComboBoxJob.ResetText()
22
23 Dim da2 As New SqlDataAdapter
24 Dim dt As New DataTable
25 Call koneksi()
26 cmd = New SqlCommand("select * From TblJob", conn)
27 da2.SelectCommand = cmd
28 da2.Fill(dt)
29 ComboBoxJob.DataSource = dt
30 ComboBoxJob.DisplayMember = "JobName"
31 ComboBoxJob.ValueMember = "ID"
32 'ComboBoxJob.SelectedValue = DataGridView1.CurrentRow.Cells
(0).Value.ToString
33
34 End Sub
35 Public Sub loaddata()
36 Call koneksi()
37 da = New SqlDataAdapter("select * from TblUser", conn)
38 ds = New DataSet
39 ds.Clear()
40 da.Fill(ds, "TblUser")
41 DataGridView1.DataSource = (ds.Tables("TblUser"))
42 End Sub
43
44 Private Sub ButtonUpdate_Click(sender As Object, e As EventArgs)
Handles ButtonUpdate.Click
45 TextBoxID.Text = DataGridView1.CurrentRow.Cells
(0).Value.ToString
46 TextBoxUsername.Text = DataGridView1.CurrentRow.Cells
(1).Value.ToString
47 TextBoxPassword.Text = DataGridView1.CurrentRow.Cells
(2).Value.ToString
C:\Users\Lenovo7\Documents\Project\002\002\Sambung.vb 2
48 ComboBoxJob.Text = DataGridView1.CurrentRow.Cells
(3).Value.ToString
49
50
51 ButtonInsert.Enabled = False
52 ButtonUpdate.Enabled = False
53 ButtonDelete.Enabled = False
54 ButtonSave.Enabled = True
55 ButtonCancel.Enabled = True
56 TextBoxUsername.Enabled = True
57 TextBoxPassword.Enabled = True
58 TextBoxID.Enabled = True
59 ComboBoxJob.Enabled = True
60 TextBoxMode.Text = "Update"
61
62 Dim da2 As New SqlDataAdapter
63 Dim dt As New DataTable
64 Call koneksi()
65 cmd = New SqlCommand("select * From TblJob", conn)
66 da2.SelectCommand = cmd
67 da2.Fill(dt)
68 ComboBoxJob.DataSource = dt
69 ComboBoxJob.DisplayMember = "JobName"
70 ComboBoxJob.ValueMember = "ID"
71 ComboBoxJob.SelectedValue = DataGridView1.CurrentRow.Cells
(3).Value.ToString
72
73
74 End Sub
75
76 Private Sub ButtonDelete_Click(sender As Object, e As EventArgs)
Handles ButtonDelete.Click
77 TextBoxID.Text = DataGridView1.CurrentRow.Cells
(0).Value.ToString
78 TextBoxUsername.Text = DataGridView1.CurrentRow.Cells
(1).Value.ToString
79 TextBoxPassword.Text = DataGridView1.CurrentRow.Cells
(2).Value.ToString
80 ComboBoxJob.Text = DataGridView1.CurrentRow.Cells
(3).Value.ToString
81 Dim Pesanperingatan As String
82 Pesanperingatan = MsgBox("Yakin Ingin Menghapus?",
83 MsgBoxStyle.YesNo, "Peringatan")
84 If Pesanperingatan = vbYes Then
85 Call koneksi()
86 Dim deleteQuery As String = "DELETE FROM TblUser WHERE
87 id = '" & TextBoxID.Text & "'"
88 cmd = New SqlCommand(deleteQuery, conn)
89 cmd.ExecuteNonQuery()
90 conn.Close()
91 MsgBox("Data DELETE")
92 loaddata()
93 TextBoxUsername.Clear()
C:\Users\Lenovo7\Documents\Project\002\002\Sambung.vb 3
94 TextBoxPassword.Clear()
95 TextBoxID.Clear()
96 ComboBoxJob.ResetText()
97 TextBoxMode.Clear()
98 TextBoxID.Clear()
99 TextBoxUsername.Clear()
100 TextBoxPassword.Clear()
101 ComboBoxJob.ResetText()
102 ElseIf Pesanperingatan = vbNo Then
103 TextBoxUsername.Clear()
104 TextBoxPassword.Clear()
105 TextBoxID.Clear()
106 ComboBoxJob.ResetText()
107 TextBoxMode.Clear()
108 TextBoxID.Clear()
109 TextBoxUsername.Clear()
110 TextBoxPassword.Clear()
111 ComboBoxJob.ResetText()
112 End If
113
114 End Sub
115
116 Private Sub ButtonSave_Click(sender As Object, e As EventArgs)
Handles ButtonSave.Click
117 If TextBoxMode.Text = "Insert" Then
118 Call koneksi()
119 Dim daftarQuery As String = "insert into TblUser
120 (Username,Password,JobID) values
121 ('" & TextBoxUsername.Text & "','" & TextBoxPassword.Text & "','" &
ComboBoxJob.SelectedValue & "')"
122 cmd = New SqlCommand(daftarQuery, conn)
123 cmd.ExecuteNonQuery()
124 conn.Close()
125 MsgBox("Data Inserted")
126 loaddata()
127 ButtonInsert.Enabled = False
128 ButtonUpdate.Enabled = False
129 ButtonDelete.Enabled = False
130 ButtonSave.Enabled = True
131 ButtonCancel.Enabled = True
132 TextBoxUsername.Enabled = True
133 TextBoxPassword.Enabled = True
134 TextBoxID.Enabled = True
135 ComboBoxJob.Enabled = True
136 TextBoxMode.Clear()
137 TextBoxID.Clear()
138 TextBoxUsername.Clear()
139 TextBoxPassword.Clear()
140 ComboBoxJob.ResetText()
141
142 ElseIf TextBoxMode.Text = "Update" Then
143 Call koneksi()
144 Dim updateQuery As String = "UPDATE TblUser SET
C:\Users\Lenovo7\Documents\Project\002\002\Sambung.vb 4
145 Username = '" & TextBoxUsername.Text & "' , Password = '" &
TextBoxPassword.Text & "' ,JobID = '" & ComboBoxJob.SelectedValue &
"' WHERE id = '" & TextBoxID.Text & "'"
146 cmd = New SqlCommand(updateQuery, conn)
147 cmd.ExecuteNonQuery()
148 conn.Close()
149 MsgBox("Data Update")
150 loaddata()
151 TextBoxMode.Clear()
152 TextBoxID.Clear()
153 TextBoxUsername.Clear()
154 TextBoxPassword.Clear()
155 ComboBoxJob.ResetText()
156 End If
157
158 End Sub
159
160 Private Sub ButtonCancel_Click(sender As Object, e As EventArgs)
Handles ButtonCancel.Click
161 ButtonInsert.Enabled = True
162 ButtonUpdate.Enabled = True
163 ButtonDelete.Enabled = True
164 ButtonSave.Enabled = False
165 ButtonCancel.Enabled = False
166 TextBoxUsername.Enabled = False
167 TextBoxPassword.Enabled = False
168 TextBoxID.Enabled = False
169 ComboBoxJob.Enabled = False
170 TextBoxMode.Clear()
171 TextBoxID.Clear()
172 TextBoxUsername.Clear()
173 TextBoxPassword.Clear()
174 ComboBoxJob.ResetText()
175 End Sub
176
177 Private Sub Sambung_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
178 loaddata()
179
180 End Sub
181 End Class

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy