Chargement Excel dans DataGridView
Bonjour à tous,
J'ai un petit problème pour avancer sur mon projet.
Je voudrait charger un fichier Excel dans un DataGridView,
Pour cela j'ai mis en place une connexion ODBC avec le fichier désiré
Le problème c'est que la connexion n'a à priori aucune erreur,
Mais lorsque je clique sur le bouton de chargement du fichier,
Rien ne s'affiche dans mon DataGridView.
Le fichier Excel est un export d'un Logiciel.
Voici le code mis en place
Code:
1 2 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 40 41 42 43 44 45 46 47 48 49 50 51 52
| Imports Excel
Imports System.Data.Odbc
Imports System.Data
Public Class Checker_win2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
main_win.Show()
Me.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
scanbox.Clear()
scanbox.Select()
End Sub
Private Sub scanbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles scanbox.TextChanged
End Sub
Private odbcConn As OdbcConnection
Private BSource As BindingSource
Private DAdapter As OdbcDataAdapter
Private DTable As DataSet 'Je ne suis pas sur du DataSet car dans le script D'origine c'était un DataTable
Private odbcCmd As OdbcCommand
Private Sub LoadRess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadRess.Click
odbcConn = New OdbcConnection("dsn=HI")
Try
odbcConn.Open()
odbcCmd = New OdbcCommand("SELECT * FROM [A$]", odbcConn)
BSource = New BindingSource()
DAdapter = New OdbcDataAdapter()
DAdapter.SelectCommand = odbcCmd
DTable = New DataSet 'Idem que pour le DataSet au dessus
DAdapter.Fill(DTable)
BSource.DataSource = DTable
With Ress
.DataSource = BSource
.AllowDrop = True
.AllowUserToAddRows = True
.AllowUserToDeleteRows = True
.AllowUserToOrderColumns = True
.AllowUserToResizeColumns = True
.AllowUserToResizeRows = True
.AutoGenerateColumns = True
End With
Catch ex As Exception
MessageBox.Show("Erreur " & ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
End Sub
End Class |
Merci d'avance pour votre aide