Bonjour,
j'ai une requete SQL qui fonctionne correctement dans SQL SERVER :
j'aimerais l’exécuter après clique d'un bouton en c#. j'ai donc fait une petite méthode mais j'ai l'impression d'avoir oublié un truc.
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
60
61
62
63
64
65
66
67
68
69
70 DELETE FROM [dbo].[doc_scanne] GO INSERT INTO [dbo].[doc_scanne] ([NumeroBC] ,[NumeroDoc] ,[NumeroBL] ,[DateFact] ,[NumeroLigne] ,[TypeDoc] ,[RefDoc] ,[RefArticle] ,[Designation] ,[Famille] ,[CaTTC] ,[Qtes] ,[Marge] ,[DateBc] ,[DateBl] ,[RefArtLigne] ,[DesignationLigne]) (SELECT b.VL_DLPIECEBC as NumeroBC, a.V_DOCNUM as NumeroDoc, b.VL_DLPIECEBL as NumeroBL, a.V_DOCDATE as DateFact, b.VL_DLNO as NumeroLigne, a.V_TYPE as TypeDoc, a.V_DOREF as RefDoc, c.ART_NUM as RefArticle, c.ART_LIB as Designation, d.FA_Intitule as Famille, sum(b.CATTCNet) as CaTTC, sum(b.QteVendues) as Qtes, sum(b.Marge) as Marge, b.VL_DLDATEBC as DateBC, b.VL_DATEBL as DateBL, e.AR_Ref as RefArtLigne, e.DL_Design as DesignationLigne FROM [NOM_SERVEUR].[TESTCOMMUNICATION1].dbo.DP_VENTES AS a, [NOM_SERVEUR].[TESTCOMMUNICATION1].dbo.DP_VENTES_LIGNES as b, [NOM_SERVEUR].[TESTCOMMUNICATION1].dbo.DP_ARTICLES as c, [NOM_SERVEUR].[TESTCOMMUNICATION1].dbo.F_FAMILLE as d, [NOM_SERVEUR].[TESTCOMMUNICATION1].dbo.F_DOCLIGNE as e WHERE ( a.V_DOCTYPE=b.VL_DOCTYPE ) AND ( b.VL_ART_UK=c.ART_UK ) AND ( d.FA_CODEFAMILLE=c.ART_FACODEFAMILLE ) AND ( a.V_DOCNUMBIN=b.VL_DOCNUMBIN ) AND ( d.FA_Type=0 ) AND ( b.VL_PK=e.CBMARQ ) AND ( a.V_DOCNUM = 'BCIV00002' ) GROUP BY b.VL_DLPIECEBC, a.V_DOCNUM, b.VL_DLPIECEBL, a.V_DOCDATE, b.VL_DLNO, a.V_TYPE, a.V_DOREF, c.ART_NUM, c.ART_LIB, d.FA_Intitule, b.VL_DLDATEBC, b.VL_DATEBL, e.AR_Ref, e.DL_Design) GOj'ai essayé d'enlevé les GO pour voir, de ne pas mettre d'initial catalog ou de prendre master comme catalog mais ça n'a pas marché. Et initialement je prenais comme catalog la base de donnée dans laquelle je fait l'INSERT mais j'ai eu le même résultat :
Quand j'appuie sur la touche entrée pour exécuter ma méthode j'obtient : "an unhandled exception just occured. syntaxe incorrecte vers NOM_SERVEUR." je pense que ça doit venir de la manière dont je me connecte à ma base et au fait que je veux requêter mon serveur lié mais que dois-je remplacer dans mon code pour que ça marche du coup ?
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 public void AlimenterTableDocumentScanne(string str_NumeroDoc) { using (SqlConnection connection = new SqlConnection("Data Source=DESKTOP-30IDPHO\\SQLEXPRESS;Integrated Security=True")) { String query = "INSERT INTO [dbo].[doc_scanne]" + " ([NumeroBC]" + " ,[NumeroDoc]" + " ,[NumeroBL]" + " ,[DateFact]" + " ,[NumeroLigne]" + " ,[TypeDoc]" + " ,[RefDoc]" + " ,[RefArticle]" + " ,[Designation]" + " ,[Famille]" + " ,[CaTTC]" + " ,[Qtes]" + " ,[Marge]" + " ,[DateBc]" + " ,[DateBl]" + " ,[RefArtLigne]" + " ,[DesignationLigne])" + "(SELECT b.VL_DLPIECEBC as NumeroBC," + " a.V_DOCNUM as NumeroDoc," + " b.VL_DLPIECEBL as NumeroBL," + " a.V_DOCDATE as DateFact," + " b.VL_DLNO as NumeroLigne," + " a.V_TYPE as TypeDoc," + " a.V_DOREF as RefDoc," + " c.ART_NUM as RefArticle," + " c.ART_LIB as Designation," + " d.FA_Intitule as Famille," + " sum(b.CATTCNet) as CaTTC," + " sum(b.QteVendues) as Qtes," + " sum(b.Marge) as Marge," + " b.VL_DLDATEBC as DateBC," + " b.VL_DATEBL as DateBL," + " e.AR_Ref as RefArtLigne," + " e.DL_Design as DesignationLigne" + "FROM" + " [NOM_SERVEUR].[TESTCOMMUNICATION1].dbo.DP_VENTES AS a," + " [NOM_SERVEUR].[TESTCOMMUNICATION1].dbo.DP_VENTES_LIGNES as b," + " [NOM_SERVEUR].[TESTCOMMUNICATION1].dbo.DP_ARTICLES as c," + " [NOM_SERVEUR].[TESTCOMMUNICATION1].dbo.F_FAMILLE as d," + " [NOM_SERVEUR].[TESTCOMMUNICATION1].dbo.F_DOCLIGNE as e" + "WHERE" + " ( a.V_DOCTYPE=b.VL_DOCTYPE )" + " AND ( b.VL_ART_UK=c.ART_UK )" + " AND ( d.FA_CODEFAMILLE=c.ART_FACODEFAMILLE )" + " AND ( a.V_DOCNUMBIN=b.VL_DOCNUMBIN )" + " AND ( d.FA_Type=0 )" + " AND ( b.VL_PK=e.CBMARQ )" + " AND (" + " a.V_DOCNUM = 'BICV00002'" + " )" + "GROUP BY" + " b.VL_DLPIECEBC, " + " a.V_DOCNUM, " + " b.VL_DLPIECEBL, " + " a.V_DOCDATE, " + " b.VL_DLNO, " + " a.V_TYPE, " + " a.V_DOREF, " + " c.ART_NUM, " + " c.ART_LIB, " + " d.FA_Intitule, " + " b.VL_DLDATEBC, " + " b.VL_DATEBL, " + " e.AR_Ref, " + " e.DL_Design)"; using (SqlCommand command = new SqlCommand(query, connection)) { connection.Open(); int result = command.ExecuteNonQuery(); // Check Error if (result < 0) Console.WriteLine("Error inserting data into Database!"); } } }
Et aussi c'est possible de mettre le mot clé GO ou faire une query avec plusieurs requêtes comme dans mon exemple ou je dois faire plusieurs query ?
Merci à ceux qui prendront la peine de me lire et de me dépanner car je sèche un peu là.
Partager