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.
Previously we had to add the recordset in module1 to contain temporary data that we use for validation and for other purposes.
To add a code input double click on the save button is CommandButton1 window will appear like this:
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 = &quot;Insert into siswa values('&quot; &amp; Me.Text1 &amp; &quot;','&quot; &amp; Me.Text2 &amp; &quot;','&quot; &amp; Me.Text3 &amp; &quot;')&quot; CONN.Execute SQLInput End Sub
Next add the source code on the button Hapus:
Private Sub Command2_Click() Dim SQLHapus As String SQLHapus= &quot;Delete from Siswa where NIS='&quot; &amp; Me.Text1 &amp; &quot;'&quot; 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 = &quot;Update siswa set nama_siswa='&quot; &amp; Me.Text2 &amp; &quot;',tempat_lahir='&quot; &amp; Me.Text3 &amp; &quot;' where NIS='&quot; &amp; Me.Text1 &amp; &quot;'&quot; CONN.Execute SQLUbah End Sub
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 = &quot;Select * from siswa where NIS='&quot; &amp; Me.Text1 &amp; &quot;'&quot; 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 = &quot;&quot; &amp; RSSiswa!nis Me.Text2 = &quot;&quot; &amp; RSSiswa!nama_siswa Me.Text3 = &quot;&quot; &amp; RSSiswa!tempat_lahir Me.Text4 = &quot;&quot; &amp; RSSiswa!tanggal_lahir Me.Text5 = &quot;&quot; &amp; RSSiswa!nama_wali Me.Text6 = &quot;&quot; &amp; RSSiswa!pekerjaan_wali Me.Text7 = &quot;&quot; &amp; RSSiswa!alamat End If End Sub Sub DataBaru() Me.Text2 = &quot;&quot; Me.Text3 = &quot;&quot; Me.Text4 = &quot;&quot; Me.Text5 = &quot;&quot; Me.Text6 = &quot;&quot; Me.Text7 = &quot;&quot; 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.