Bonjour
Bon voila le code qui permet de lire un fichier Excel sur vb.net mais
Le problème c est qu'on met une virgule ou bien autre chose
Dans cette commande cmd1.commandetext=("select *from [janvier$],cnexl)
voila le code complet
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class Form3
Dim cnexel As New OleDbConnection
Dim cnsql As New SqlConnection
Dim ds As New DataSet
Dim da As New OleDbDataAdapter
Dim cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8, cmd9, cmd10, cmd11, cmd12 As OleDbCommand
Dim inter1, inter2, inter3, inter4, inter5, inter6, inter7, inter8, inter9, inter10, inter11, inter12 As New SqlBulkCopy(cnsql)
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
cnexel.ConnectionString = ("provider=Microsoft.ace.OLEDB.12.0;Data Source='E:\esma\tp vb\2em control\gstcmp\gstcmp\bin\Debug\gst.xlsx';Extended Properties=Excel 12.0 xml; hdr=yes";)
'cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; data source=E:\esma\tp vb\2em control\gstcmp\gstcmp\bin\Debug\mabase.accdb"
cnsql.sqlconnection = ("data source=.;intial catalogue= & gst & ;integrated security=true")
cmd1.CommandText = ("select * from [Janvier$]",cnExel)
cmd2.CommandText=("select * from [Février$]",cnexel)
cmd3.CommandText=("select * from [Mars$]",cnexel)
cmd4.CommandText=("select * from [Avril$]",cnexel)
cmd5.CommandText=("select * from [Mai$]",cnexel)
cmd6.CommandText=("select * from [Juin$]",cnexel)
cmd7.CommandText=("select * from [Juillet$]",cnexel)
cmd8.CommandText=("select * from [Aout$]",cnexel)
cmd9.CommandText=("select * from [Septembre$]",cnexel)
cmd10.CommandText=("select * from [Octobre$]",cnexel)
cmd11.CommandText=("select * from [Novembre$]",cnexel)
cmd12.CommandText=("select * from [Decembre$]",cnexel)
da.SelectCommand = cmd1
da.Fill(ds, "table-1")
da.SelectCommand = cmd1
da.Fill(ds, "table-1")
da.SelectCommand = cmd2
da.Fill(ds, "table-2")
da.SelectCommand = cmd3
da.Fill(ds, "table-3")
da.SelectCommand = cmd4
da.Fill(ds, "table-4")
da.SelectCommand = cmd5
da.Fill(ds, "table-5")
da.SelectCommand = cmd6
da.Fill(ds, "table-6")
da.SelectCommand = cmd7
da.Fill(ds, "table-7")
da.SelectCommand = cmd8
da.Fill(ds, "table-8")
da.SelectCommand = cmd9
da.Fill(ds, "table-9")
da.SelectCommand = cmd10
da.Fill(ds, "table-10")
da.SelectCommand = cmd11
da.Fill(ds, "table-11")
da.SelectCommand = cmd12
da.Fill(ds, "table-12")
DataGridView1.DataSource = ds.Tables("table-1")
DataGridView1.DataSource = ds.Tables("table-2")
DataGridView1.DataSource = ds.Tables("table-3")
DataGridView1.DataSource = ds.Tables("table-4")
DataGridView1.DataSource = ds.Tables("table-5")
DataGridView1.DataSource = ds.Tables("table-6")
DataGridView1.DataSource = ds.Tables("table-7")
DataGridView1.DataSource = ds.Tables("table-8")
DataGridView1.DataSource = ds.Tables("table-9")
DataGridView1.DataSource = ds.Tables("table-10")
DataGridView1.DataSource = ds.Tables("table-11")
DataGridView1.DataSource = ds.Tables("table-12")
cnsql.Open()
inter1.DestinationTableName = "table-1"
inter1.WriteToServer(ds.Tables("table1"))
inter1.DestinationTableName = "table-2"
inter1.WriteToServer(ds.Tables("table2"))
inter1.DestinationTableName = "table-3"
inter1.WriteToServer(ds.Tables("table3"))
inter1.DestinationTableName = "table-4"
inter1.WriteToServer(ds.Tables("table4"))
inter1.DestinationTableName = "table-5"
inter1.WriteToServer(ds.Tables("table5"))
inter1.DestinationTableName = "table-6"
inter1.WriteToServer(ds.Tables("table6"))
inter1.DestinationTableName = "table-7"
inter1.WriteToServer(ds.Tables("table7"))
inter1.DestinationTableName = "table-8"
inter1.WriteToServer(ds.Tables("table8"))
inter1.DestinationTableName = "table-9"
inter1.WriteToServer(ds.Tables("table9"))
inter1.DestinationTableName = "table-10"
inter1.WriteToServer(ds.Tables("table10"))
inter1.DestinationTableName = "table-11"
inter1.WriteToServer(ds.Tables("table11"))
inter1.DestinationTableName = "table-12"
inter1.WriteToServer(ds.Tables("table12"))
Catch ex As Exception When MsgBox(ex.ToString)
End Try
End Sub
End Class