Add Events Input, Update, Delete, And Find Microsoft Access Database in Microsoft Visual Basic 6

After we build your Form Design in Microsoft Visual Basic 6 in the previous article we will now add Input, Update, Delete and Find Microsoft Access database in Microsoft Visual Basic 6. At this stage, usually called coding, the form that we have made will we give coding order The form can input data for the purpose of obtaining information.

All we ever did from the initial stage we will use are all here for my friends who lagged please see article ever before. Here we will use a lot of SQL queries. SQL stands for Structured Query Language. Basically SQL is a standard computer language specified by ANSI (American National Standards Institute) for accessing and manipulating database systems. SQL can work well on programs such as Ms.Access database, MS SQL Server, Oracle, and others. Versions of SQL very much but the rules remain the same used on every syntax.

And in this article we will use a lot of Data Manipulation Language (DML). DML is a group of commands used to manipulate data in a database, for example for the retrieval, insertion, modification and deletion of data. DML commands that are included in, among others:

SELECT, used to select or display data

INSERT, used to enter data

UPDATE, used to change the data

DELETE is used to delete data

Adding Events Input, Update, Delete and Find Microsoft Access Database in Microsoft Visual Basic 6 we will need a connection to the database. Stages connection we have done in the previous article Creating a Microsoft Access Database Connections Visual Basic 6.

Form Siswa

Creating Form Design in Microsoft Visual Basic 6

Previously we had to add the recordset in module1 to contain temporary data that we use for validation and for other purposes.

Adding Events Input, Update, Delete, And Find Microsoft Access Database in Microsoft Visual Basic 6_1

To add a code input double click on the save button is CommandButton1 window will appear like this:

Adding Events Input, Update, Delete, And Find Microsoft Access Database in Microsoft Visual Basic 6

We will add the code between the Private Sub and End Sub Input to the source code as follows:

Private Sub Command1_Click()
Dim SQLInput As String
SQLInput = "Insert into siswa values('" & Me.Text1 & "','" & Me.Text2 & "','" & Me.Text3 & "')" CONN.Execute SQLInput 

End Sub

Next add the source code on the button Hapus:

Private Sub Command2_Click()
Dim SQLHapus As String 

SQLHapus= "Delete from Siswa where NIS='" & Me.Text1 & "'"
CONN.Execute SQLHapus

End Sub

Then add it again to the source code on the buttton Ubah :

Private Sub Command3_Click()
Dim SQLUbah As String 

SQLUbah = "Update siswa set nama_siswa='" & Me.Text2 & "',tempat_lahir='" & Me.Text3 & "' where NIS='" & Me.Text1 & "'"
CONN.Execute SQLUbah

End Sub

 

Information:

To change and delete, you must Find the data before change and delete so that you will be looking for data to be changed or data to be deleted.

To search the data in the textbox source code below can be used:


Private Sub CariData()
Dim SQLCari As String

SQLCari = "Select * from siswa where NIS='" & Me.Text1 & "'"
Set RSSiswa = CONN.Execute(SQLCari) 'menampung isi dari tabel siswa kedalam RSSISWA recordset

End Sub

Sub Ketemu()
Call CariData
If Not RSSiswa.EOF Then
Me.Text1 = "" & RSSiswa!nis
Me.Text2 = "" & RSSiswa!nama_siswa
Me.Text3 = "" & RSSiswa!tempat_lahir
Me.Text4 = "" & RSSiswa!tanggal_lahir
Me.Text5 = "" & RSSiswa!nama_wali
Me.Text6 = "" & RSSiswa!pekerjaan_wali
Me.Text7 = "" & RSSiswa!alamat
End If
End Sub

Sub DataBaru()
Me.Text2 = ""
Me.Text3 = ""
Me.Text4 = ""
Me.Text5 = ""
Me.Text6 = ""
Me.Text7 = ""
Me.Text2.SetFocus
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call CariData
If RSSiswa.EOF Then
Call DataBaru
Else
Call Ketemu
End If
End Sub

All over the place in the source code form students. For Adding Events Input, Update, Delete and Find Microsoft Access Database in Microsoft Visual Basic 6 was created. Thanks you.

Leave a comment