Program Tambah Record Di Visual Basic Net 2008

Silahkan buat dahulu database access :
Nama Database : SmartSolution.Mdb
Nama Table : Buku
Field
1. Kode type Text
2. Judul type Text
3. Pengarang type Text
4. Penerbit type Text

Design form Program Tambah Record Di Visual Basic Net 2008


Berikut listing Program Tambah Record Di Visual Basic Net 2008

Imports System.Data.OleDb
Public Class Form1
    Public DB As OleDbConnection
    Public CMD As OleDbCommand
    Public ADP As OleDbDataAdapter
    Public DS As New DataSet

    Public Sub OpenDB()
        Dim LOKASI = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =E:DatabaseSmartSolution.mdb"
        DB = New OleDbConnection(LOKASI)
        If DB.State = ConnectionState.Closed Then
            DB.Open()
        End If
    End Sub

    Sub TampilBuku()
          ' Pada perintah SELEC tambahkan huruf T
        ADP = New OleDbDataAdapter("SELEC * FROM Buku", DB)
        DS = New DataSet
        ADP.Fill(DS, "Buku")
        DataGridView1.DataSource = DS.Tables("Buku")
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call OpenDB()
        Call btnBaru_Click(sender, e)
        Call TampilBuku()
    End Sub

    Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
        Dim SQL As String
        SQL = "INSERT INTO Buku (Kode, Judul, Pengarang, Penerbit)" & _
                      " VALUES('" & Kode.Text & "','" & _
                                    Judul.Text & "','" & _
                                    Pengarang.Text & "','" & _
                                    Penerbit.Text & "')"

        CMD = New OleDbCommand(SQL, DB)
        CMD.ExecuteNonQuery()
        Call btnBaru_Click(sender, e)
        Call TampilBuku()
    End Sub

    Private Sub btnBaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaru.Click
        Kode.Text = ""
        Judul.Text = ""
        Pengarang.Text = ""
        Penerbit.Text = ""
    End Sub
End Class


Sumber : Mesran.net
Back to top