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 53 54 55 56
| Imports Excel
...
.
.
.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Page.Validate()
If Page.IsValid Then
'la ligne ecrit en rouge qui me cause le pobleme
Dim ClasseurXLS As New Excel.Application
chaine_con = ConfigurationSettings.AppSettings("Siteindic")
Dim con As New SqlConnection(chaine_con)
Dim iNom_emp(,) As String
Dim file_xsl As String = lien.Text
Dim fichier_excel As String
fichier_excel = file_xsl.Substring(file_xsl.LastIndexOf("\") + 1)
Try
ClasseurXLS.Workbooks.Open(file_xsl)
Catch ex As Exception
Label1.Visible() = True
Label1.Text = ex.Message
End Try
Dim i As Integer
i = 2
Dim a As Integer
Dim a1, a2, a3, a4, a5 As String
a = ClasseurXLS.Cells(i, 1).Value()
Dim t As Integer
Try
con.Open()
While CType(ClasseurXLS.Cells(i, 1).value(), String) <> ""
'Recuperation des données lignes par lignes
a = CType(ClasseurXLS.Cells(i, 1).value(), Integer)
a1 = CType(ClasseurXLS.Cells(i, 2).value(), String)
a2 = CType(ClasseurXLS.Cells(i, 3).value(), String)
a2 = a2.Replace("'", "''")
a3 = CType(ClasseurXLS.Cells(i, 4).value(), String)
a4 = CType(ClasseurXLS.Cells(i, 5).value(), String)
a5 = CType(ClasseurXLS.Cells(i, 6).value(), String)
'Insertion des données dans la table
Dim requete As String
requete = "INSERT INTO Table1 (id,val1,val2,val3) values (" & a & ",'" & a1 & "', '" & a2 & "' , '" & a3 & "')"
Dim cmd As New SqlCommand(requete, con)
cmd.ExecuteNonQuery()
i = i + 1
End While
Catch ex As Exception
Label1.Visible() = True
Label1.Text = ex.Message
Finally
con.Close()
End Try
MsgBox(i)
End If
End Sub |
Partager