Advertisement
stevennathaniel

EXCEL : Input Data Dari TextBox Menggunakan ACE.OLEDB

Feb 16th, 2016
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.75 KB | None | 0 0
  1. Imports System.Data.OleDb
  2.  
  3. Imports System.Data
  4.  
  5. Public Class Form5
  6.  
  7.     'Dim oledbKoneksi As OleDbConnection = New OleDbConnection
  8.  
  9.     'Dim oledbPerintah As OleDbCommand = New OleDbCommand
  10.  
  11.     'Dim lokasiFile As String = "D:\fileExcel"
  12.  
  13.     'Dim namaFile As String = "LatihanOLEDB2.xlsx"
  14.  
  15.     'Dim stringKoneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source" & lokasiFile & namaFile & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
  16.  
  17.  
  18.  
  19.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  20.  
  21.         Dim Nama As String
  22.  
  23.         Dim Alamat As String
  24.  
  25.         Nama = TextBox1.Text
  26.  
  27.         Alamat = TextBox2.Text
  28.  
  29.         Dim oledbKoneksi As OleDbConnection = New OleDbConnection
  30.  
  31.         Dim oledbPerintah As OleDbCommand = New OleDbCommand
  32.  
  33.         Dim lokasiFile As String = "D:\fileExcel\"
  34.  
  35.         Dim namaFile As String = "LatihanOLEDB2.xlsx"
  36.  
  37.         Dim stringKoneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & lokasiFile & namaFile & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
  38.  
  39.  
  40.         oledbKoneksi.ConnectionString = stringKoneksi
  41.  
  42.         oledbKoneksi.Open()
  43.  
  44.         oledbPerintah.Connection = oledbKoneksi
  45.  
  46.         'oledbPerintah.CommandText = "CREATE TABLE DataKaryawan (Nama VARCHAR, " & "Alamat VARCHAR)"
  47.  
  48.         'oledbPerintah.ExecuteNonQuery()
  49.  
  50.  
  51.         oledbPerintah.CommandText = "INSERT INTO DataKaryawan (Nama, Alamat) values " & "('" & Nama & "', '" & Alamat & "')"
  52.  
  53.         oledbPerintah.ExecuteNonQuery()
  54.  
  55.  
  56.         oledbKoneksi.Close()
  57.  
  58.  
  59.  
  60.  
  61.         MessageBox.Show("File yg bernama " & namaFile & "telah berhasil diciptakan dan diletakan di " & lokasiFile)
  62.  
  63.      
  64.  
  65.     End Sub
  66. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement