Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.OleDb
- Imports System.Data
- Public Class Form4
- Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
- Dim oleCon As OleDbConnection = New OleDbConnection
- Dim olecmd As OleDbCommand = New OleDbCommand
- Dim filePath As String = "D:\fileExcel\"
- Dim fileName As String = "LatihanOLEDB1.xlsx"
- 'Construct your connection string
- Dim connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & filePath & fileName & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
- oleCon.ConnectionString = connstring
- oleCon.Open()
- olecmd.Connection = oleCon
- ' Command to create the table
- 'olecmd.CommandText = "CREATE TABLE Sheet6(Sno Int, " & "Employee_Name VARCHAR, " & "Company VARCHAR, " & "Date_of_joining DATE, " & "Stipend DECIMAL, " & "Stock_Held DECIMAL)"
- 'olecmd.ExecuteNonQuery()
- 'Adding Data
- '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')"
- 'olecmd.ExecuteNonQuery()
- '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')"
- 'olecmd.ExecuteNonQuery()
- 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')"
- olecmd.ExecuteNonQuery()
- oleCon.Close()
- MessageBox.Show("The file " & fileName & " has been created successfully and has been placed in " & filePath)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement