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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| ' tout ça c'est au niveau du module ;)
Imports System.Data.OleDb
Imports System.Data.SqlClient
Module Module1
Public cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Classeur1.xls;Extended Properties=Excel 8.0")
Public cn1 As New SqlConnection("Data Source=EODELL-PC;Initial Catalog=projet;Integrated Security=true")
Public ds As New DataSet
' en ce qui concerne la forme voila son code !!
Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class Form1
Dim daa As New OleDbDataAdapter("select * from [Feuil1$]", cn)
Dim da As New SqlDataAdapter("select * from Employé", cn1)
Dim cb As New SqlCommandBuilder(da)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
daa.Fill(ds, "[Feuil1$]")
da.Fill(ds, "Employé")
' ca c'est pour la 2éme méthode dont je vous ai parlé au dessus : supprimer 'tout les enregisrements de la BD sql
'Try
' For i = 1 To ds.Tables("Employé").Rows.Count
' 'Dim l As DataRow = ds.Tables("Employé").Rows(i)
' ds.Tables("Employé").Rows.RemoveAt(i)
' Next
'Catch ex As Exception
' MsgBox(ex.Message)
'End Try
'da.Update(ds, "Employé")
End Sub
' ça c'est le boutton importer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim z As Boolean = False
For Each ee As DataRow In ds.Tables("[Feuil1$]").Rows
For i = 0 To ds.Tables("Employé").Rows.Count - 1
Dim l As DataRow = ds.Tables("Employé").Rows(i)
If l(1) = ee(1) Then
l.BeginEdit()
l(1) = ee(1)
l(2) = ee(2)
l(3) = ee(3)
l(4) = ee(4)
l(5) = ee(5)
l(6) = ee(6)
l(7) = ee(7)
l(8) = ee(8)
l(9) = ee(9)
l(10) = ee(10)
l.EndEdit()
z = True
End If
Next
If z = False Then
Dim dr As DataRow = ds.Tables("Employé").NewRow
dr(0) = ee(0)
dr(1) = ee(1)
dr(2) = ee(2)
dr(3) = ee(3)
dr(4) = ee(4)
dr(5) = ee(5)
dr(6) = ee(6)
dr(7) = ee(7)
dr(8) = ee(8)
dr(9) = ee(9)
dr(10) = ee(10)
ds.Tables("Employé").Rows.Add(dr)
End If
Next
da.Update(ds, "Employé") |
Partager