Dim olecon As OleDbConnection = New OleDbConnection
Dim olecmd As OleDbCommand = New OleDbCommand
Dim FilePath As String = "C:\Temp\"
Dim FileName As String = "PLCTags.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
Dim FEUILLE As String = "PLC Tags"
'~~> Command to create the table
olecmd.CommandText = "CREATE TABLE" & FEUILLE & " (Name VARCHAR, Path VARCHAR, Data Type VARCHAR, Logical Address VARCHAR, Comment VARCHAR, Hmi Visible VARCHAR, Hmi Accessible VARCHAR)"
olecmd.ExecuteNonQuery()
'~~> Adding Data
'~~> Close the connection
olecon.Close()
'~~> Inform User
MessageBox.Show("The file " & FileName & " has been created successfully and has been placed in " & FilePath)
'~~> Command to create the table
olecmd.CommandText = "CREATE TABLE [PLC Tags] (Name VARCHAR, Path VARCHAR, Data Type VARCHAR, Logical Address VARCHAR, Comment VARCHAR, Hmi Visible VARCHAR, Hmi Accessible VARCHAR)"
olecmd.ExecuteNonQuery()
Option Strict On Imports System.Data.OleDb Public Class Form1 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 = "C:\Temp\" Dim FileName As String = "PLCTags.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 Dim FEUILLE As String = " PLCTags " '~~> Command to create the table olecmd.CommandText = "CREATE TABLE " & FEUILLE & " (Id char(255), Name char(255), BirthDate date)" olecmd.ExecuteNonQuery() olecmd.CommandText = "INSERT INTO " & FEUILLE & " (Id, Name, BirthDate) values ('AAA', 'Andrew', '12/4/1955')" olecmd.ExecuteNonQuery() '~~> Close the connection olecon.Close() '~~> Inform User MessageBox.Show("The file " & FileName & " has been created successfully and has been placed in " & FilePath) End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question