SHARE
TWEET

ACE OLEDB 12 : Berhasil Input Multiple Data Ke Excel 2010

stevennathaniel Feb 16th, 2016 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Data.OleDb
  2.  
  3. Imports System.Data
  4.  
  5. Public Class Form4
  6.  
  7.  
  8.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  9.  
  10.         Dim oleCon As OleDbConnection = New OleDbConnection
  11.  
  12.         Dim olecmd As OleDbCommand = New OleDbCommand
  13.  
  14.         Dim filePath As String = "D:\fileExcel\"
  15.  
  16.         Dim fileName As String = "LatihanOLEDB1.xlsx"
  17.  
  18.  
  19.         'Construct your connection string
  20.  
  21.         Dim connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & filePath & fileName & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
  22.  
  23.         oleCon.ConnectionString = connstring
  24.  
  25.         oleCon.Open()
  26.  
  27.         olecmd.Connection = oleCon
  28.  
  29.  
  30.         ' Command to create the table
  31.  
  32.         'olecmd.CommandText = "CREATE TABLE Sheet6(Sno Int, " & "Employee_Name VARCHAR, " & "Company VARCHAR, " & "Date_of_joining DATE, " & "Stipend DECIMAL, " & "Stock_Held DECIMAL)"
  33.  
  34.         'olecmd.ExecuteNonQuery()
  35.  
  36.  
  37.         'Adding Data
  38.  
  39.         'olecmd.CommandText = "INSERT INTO Sheet5(Sno, Employee_Name, Company,Date_Of_joining,Stipend,Stock_Held) values " & "('1', 'Siddharth Rout', 'Defining Horizons', '20/7/2014','2000.75','0.01')"
  40.  
  41.         'olecmd.ExecuteNonQuery()
  42.  
  43.         'olecmd.CommandText = "INSERT INTO Sheet5(Sno, Employee_Name, Company,Date_Of_joining,Stipend,Stock_Held) values " & "('2', 'Steven Nathaniel', 'Matahari TBK', '21/7/2016','2000.80','0.02')"
  44.  
  45.         'olecmd.ExecuteNonQuery()
  46.  
  47.         olecmd.CommandText = "INSERT INTO Sheet5(Sno, Employee_Name, Company,Date_Of_joining,Stipend,Stock_Held) values " & "('3', 'Septivia Crestfall', 'DOTA2', '23/8/2015','2000.89','0.03')"
  48.  
  49.         olecmd.ExecuteNonQuery()
  50.  
  51.         oleCon.Close()
  52.  
  53.         MessageBox.Show("The file " & fileName & " has been created successfully and has been placed in " & filePath)
  54.  
  55.  
  56.     End Sub
  57. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top