insert data, update data, dan hapus data di module

Option Explicit
Public CN As New ADODB.connection
Public RS As New ADODB.Recordset
Public Function connection()
CN.Open “Driver={SQL Server}; ” & _
“Server=plick; ” & _
“Database=testing; ” & _
“UID=sa; ” & _
“PWD=plick”
RS.CursorLocation = adUseClient
End Function

koding dia atas untuk menghubungkan ke database

insert data

Public Function insert(ByVal nama As String, ByVal alamat As String, ByVal telepon As String)
With RS
CN.Execute “insert into t_person (nama,alamat,telepon) values (‘” & nama & “‘,'” & alamat & “‘,'” & telepon & “‘)”
.Requery
End With
End Function

update data

Public Function update(ByVal nama As String, ByVal alamat As String, ByVal telepon As String)
With RS
CN.Execute “update t_person set alamat='” & alamat & “‘,telepon='” & telepon & “‘ where nama='” & nama & “‘”
.Requery
End With
End Function

delete data

Public Function delete(ByVal nama As String)
With RS
CN.Execute “delete from t_person where nama='” & nama & “‘”
.Requery
End With
End Function

jadi di objek button kalo mo insert tinggal ngelempar aja

Code:
Private Sub Command1_Click()
insert Text1.Text, Text2.Text, Text3.Text
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s