Salut tout le monde,
Je veux importer des données à partir d'une base de données SQL Server et les enregistrer sous 3 BD SQL différentes "Chacune selon une requete spécifiée"
J'ai écrit ce code VB :
Mais quand je lance l'application, une erreur se produit ! comme vous voyez ci-dessous :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim CnxExcel As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & TextBox1.Text & ";Extended Properties=""Excel 12.0 XML;HDR=YES"";") Dim CnxSQLBDQ1 As New SqlConnection("Data Source=AIMAN-PC;Initial Catalog=BD_Globale_Query1;Integrated security=True") Dim CnxSQLBDQ2 As New SqlConnection("Data Source=AIMAN-PC;Initial Catalog=BD_Globale_Query2;Integrated security=True") Dim CnxSQLBDQ3 As New SqlConnection("Data Source=AIMAN-PC;Initial Catalog=BD_Globale_Query3;Integrated security=True") Dim CnxSQL As New SqlConnection("Data Source=AIMAN-PC;Initial Catalog=BD_Globale;Integrated security=True") Dim da As New OleDbDataAdapter Dim ds As New DataSet Dim cmd As New OleDbCommand("Select * from [Globale$]", CnxExcel) da.SelectCommand = cmd da.Fill(ds, "Globale") DataGridView1.DataSource = ds.Tables("Globale") Dim InterTest As New SqlBulkCopy(CnxSQL) CnxSQL.Open() InterTest.DestinationTableName = "dbo.Globale" InterTest.WriteToServer(ds.Tables("Globale")) CnxSQLBDQ1.Open() Dim Q1 As String = "SELECT * FROM Globale Where Maille<=500 AND [PP(m)]>=0.4 AND [BPL/B(%)]>=40 " Dim CQ1 As SqlCommand = New SqlCommand(Q1, CnxSQLBDQ1) Dim ReaderQ1 As SqlDataReader ReaderQ1 = CQ1.ExecuteReader() ReaderQ1.Read() ReaderQ1.GetValue(0) Dim InterQ1 As New SqlBulkCopy(CnxSQLBDQ1) InterQ1.DestinationTableName = "Globale1" InterQ1.WriteToServer(ReaderQ1) CnxSQLBDQ1.Close() CnxSQLBDQ2.Open() Dim Q2 As String = "SELECT * FROM Global Where Maille>=800 AND Maille<=2000 AND [PP(m)]>=0.4 AND [BPL/B(%)]>=40 " Dim CQ2 As SqlCommand = New SqlCommand(Q2, CnxSQLBDQ2) Dim ReaderQ2 As SqlDataReader ReaderQ2 = CQ2.ExecuteReader() ReaderQ2.Read() ReaderQ2.GetValue(0) Dim InterQ2 As New SqlBulkCopy(CnxSQLBDQ2) InterQ2.DestinationTableName = "Globale2" InterQ2.WriteToServer(ReaderQ2) CnxSQLBDQ2.Close() CnxSQLBDQ3.Open() Dim Q3 As String = "SELECT * FROM Global Where Maille>2000 AND [PP(m)]>=0.4 AND [BPL/B(%)]>=40 " Dim CQ3 As SqlCommand = New SqlCommand(Q3, CnxSQLBDQ3) Dim ReaderQ3 As SqlDataReader ReaderQ3 = CQ3.ExecuteReader() ReaderQ3.Read() ReaderQ3.GetValue(0) Dim InterQ3 As New SqlBulkCopy(CnxSQLBDQ3) InterQ3.DestinationTableName = "Globale3" InterQ3.WriteToServer(ReaderQ3) CnxSQLBDQ3.Close() End Sub
Aidez moi SVP ! Merci d'avance![]()
Partager