Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.OleDb
- Imports System.Data
- Public Class Form5
- 'Dim oledbKoneksi As OleDbConnection = New OleDbConnection
- 'Dim oledbPerintah As OleDbCommand = New OleDbCommand
- 'Dim lokasiFile As String = "D:\fileExcel"
- 'Dim namaFile As String = "LatihanOLEDB2.xlsx"
- 'Dim stringKoneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source" & lokasiFile & namaFile & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
- Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
- Dim Nama As String
- Dim Alamat As String
- Nama = TextBox1.Text
- Alamat = TextBox2.Text
- Dim oledbKoneksi As OleDbConnection = New OleDbConnection
- Dim oledbPerintah As OleDbCommand = New OleDbCommand
- Dim lokasiFile As String = "D:\fileExcel\"
- Dim namaFile As String = "LatihanOLEDB2.xlsx"
- Dim stringKoneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & lokasiFile & namaFile & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
- oledbKoneksi.ConnectionString = stringKoneksi
- oledbKoneksi.Open()
- oledbPerintah.Connection = oledbKoneksi
- 'oledbPerintah.CommandText = "CREATE TABLE DataKaryawan (Nama VARCHAR, " & "Alamat VARCHAR)"
- 'oledbPerintah.ExecuteNonQuery()
- oledbPerintah.CommandText = "INSERT INTO DataKaryawan (Nama, Alamat) values " & "('" & Nama & "', '" & Alamat & "')"
- oledbPerintah.ExecuteNonQuery()
- oledbKoneksi.Close()
- MessageBox.Show("File yg bernama " & namaFile & "telah berhasil diciptakan dan diletakan di " & lokasiFile)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement