| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 
 | Imports System.Data.SqlClient
Imports System.Data.OleDb
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.OpenFileDialog1.ShowDialog()
        Me.TextBox1.Text = Me.OpenFileDialog1.FileName
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim CnxExel As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Me.TextBox1.Text & ";Extended Properties=""Excel 12.0 Xml;HDR=YES"";")
        Dim CnxSql As New SqlConnection("Data Source=(local);Initial Catalog=EA_Data_Base;Integrated Security=True")
        Dim Cn As New OleDbDataAdapter
        Dim ds As New DataSet
        Dim cmd As New OleDbCommand("select * from [Models$]", CnxExel)
        Cn.SelectCommand = cmd
        Cn.Fill(ds, "Stag")
        Me.DataGridView1.DataSource = ds.Tables("Stag")
 
        'Initialise la connection au serveur
 
 
 
 
        Dim InterModel As New SqlBulkCopy(CnxSql)
        CnxSql.Open()
 
        Dim mappingID As New SqlBulkCopyColumnMapping("ID", "ID")
        Dim mappingElements As New SqlBulkCopyColumnMapping("Elements", "Notation_Elements")
        Dim mappingModelID As New SqlBulkCopyColumnMapping("Model ID", "Model_ID")
        Dim mappingName As New SqlBulkCopyColumnMapping("Name", "Name")
 
        InterModel.DestinationTableName = "Stag"
        InterModel.WriteToServer(ds.Tables("Stag"))
 
 
    End Sub
End Class | 
Partager