- coding module
Option Explicit
Public cn As New ADODB.Connection
Public Sub openConnection()
Set cn = New ADODB.Connection
With cn
.ConnectionString = ""
.CursorLocation = adUseClient
.Open
End With
End Sub
- coding simpan
Dim strsql As String
If Text1.Text <> "" And Text2.Text <> "" Then
strsql = "insert into siswa" & "(nis,nama)" _
& "values(' " & Text1.Text & " ',' " & Text2.Text & " ')"
cn.Execute strsql
MsgBox "Data Telah Tersimpan", vbInformation, Me.Caption
Adodc1.Refresh
Text1.Text = ""
Text2.Text = ""
Exit Sub
Else
MsgBox "DData Belum Lengkap", vbInformation, Me.Caption
Exit Sub
End If
End Sub
- coding hapus
Dim strsql As String
If MsgBox("Yakin Akan Di Hapus?" _
, vbQuestion + vbYesNo, "Hapus Data") = vbYes Then
strsql = "Delete from siswa where nis= '" & Text1.Text & "'"
cn.Execute strsql, , adCmdText
MsgBox "Data Sudah Terhapus!", vbInformation, Me.Caption
End If
Command3_Click
Exit Sub
End Sub
- coding refresh
Set Ldata = New ADODB.Recordset
Dim strsql As String
Set Ldata = Nothing
strsql = "select * from siswa order by nis desc"
Ldata.Open strsql, cn, adOpenDynamic, adLockOptimistic, adCmdText
Tampilkan_Data
End Sub
- coding tampilkan data
On Error Resume Next
With Ldata
Text1.Text = !nis
Text2.Text = !nama
End With
Set DataGrid1.DataSource = Ldata.DataSource
DataGrid1.Refresh
End Sub
ges ah sakie hela ahahahah :D
Tidak ada komentar:
Posting Komentar