IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Incorrect syntax near the keyword 'with'.


Sujet :

VB.NET

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Responsable GPAO
    Inscrit en
    Avril 2007
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable GPAO
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 4
    Points : 9
    Points
    9
    Par défaut Incorrect syntax near the keyword 'with'.
    bonjour,

    mon application creer en vb.net me donne cette erreur
    'System.Runtime.InteropServices.COMException (0x80040E14): Incorrect syntax near the keyword 'with'.
    at ADODB.RecordsetClass.Open(Object Source, Object ActiveConnection, CursorTypeEnum CursorType, LockTypeEnum LockType, Int32 Options)'
    Malgré qu'il est testé dans un autre Pc sur réseau et ça marchait sans aucune erreur
    base de donner sur sql server 2008 r2.

  2. #2
    Modérateur
    Avatar de Sankasssss
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2006
    Messages
    1 842
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 842
    Points : 4 232
    Points
    4 232
    Par défaut
    Bonjour et bienvenue sur dvp.com,

    Il nous faudrait le code source où l'erreur se déclenche pour pouvoir vous aider.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Responsable GPAO
    Inscrit en
    Avril 2007
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable GPAO
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 4
    Points : 9
    Points
    9
    Par défaut Incorrect syntax near the keyword 'with'.
    bonjour et merci pour votre réactivité rapide;
    ma code source est :
    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
    Public Sub Fill_DG()
     
            Dim rsRolls As New ADODB.Recordset
     
            DGV.Enabled = False
            DGV.Rows.Clear()
            With rsRolls
     
    next_step:
                ' Show the last roll produced
                .Open("with t1 as(select sum(isnull(poids,0)) prodm,MONTH(datefab) mois1,YEAR(datefab) an from etiquette where DATEPART(day,datefab) between '1' and '31' and YEAR(datefab)='" & CmB1.Text & "' group by MONTH(datefab),YEAR(datefab)),t2 as(select SUM(ISNULL(poids,0)) prod1,MONTH(datefab) mois,YEAR(datefab) an1 from etiquette where DATEPART(day,datefab)='1' and YEAR(datefab)='" & CmB1.Text & "'and DATEPART(hour,datefab)>= '0' and datepart(hour,datefab)<'6' group by MONTH(datefab),YEAR(datefab)),t3 as(select SUM(isnull(poids,0)) prod2,MONTH(datefab)-1  mois2,YEAR(datefab) an2 from etiquette where DATEPART(day,datefab)='1' and YEAR(datefab)='" & CmB1.Text & "'and DATEPART(hour,datefab)>= '0' and datepart(hour,datefab)<'6' group by MONTH(datefab),YEAR(datefab)),t4 as(select  t1.mois1 moisprod,T1.AN ANNEE,case when t1.prodm-t2.prod1+t3.prod2 is null then t1.prodm-t2.prod1 else t1.prodm-t2.prod1+t3.prod2 end as Production from t1 Join t2 on t1.mois1=t2.mois and t1.an=T2.an1 left Join t3 on t1.mois1=t3.mois2 AND T1.an=T3.an2),t5 as(select year(datefab)-1 anf,sum(isnull(poids,0)) tp,month(datefab)+11 mf from etiquette where datepart(day,datefab)='1'and year(datefab)='" & CmB1.Text & "'+1 and datepart(hour,datefab)>'0'and datepart(hour,datefab)<'6'and month(datefab)='1'group by year(datefab),month(datefab)),t6 as(select t4.moisprod moisprod,t4.annee ANNEE,case when round((t4.Production+t5.tp)/1000,0) is null then round(t4.Production/1000,0) else round((t4.Production+t5.tp)/1000,0) end as Production from t4 left join t5 on t4.moisprod=t5.mf and t4.annee=t5.anf) select production,moisprod from t6 where annee='" & CmB1.Text & "'", Connexion, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
                If .EOF Then GoTo enable_panel
                .MoveFirst()
                Do While Not .EOF
                    DGV.Rows.Add(.Fields("MOISPROD").Value, _
                                 .Fields("Production").Value
                                 )
     
                    .MoveNext()
                Loop
                .Close()
                DGV.Enabled = True
    enable_panel:
     
            End With
        End Sub
    le problème dans le syntaxe 'with' a noter que ma requette est tester sur sql Server management studio sans erreur

  4. #4
    Modérateur
    Avatar de Sankasssss
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2006
    Messages
    1 842
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 842
    Points : 4 232
    Points
    4 232
    Par défaut
    Votre problème se situe donc au niveau de la requête SQL :
    Code SQL : 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
     
    with t1 as(
       select sum(isnull(poids,0)) prodm,
            MONTH(datefab) mois1,
            YEAR(datefab) an 
       from etiquette 
       where DATEPART(day,datefab) between '1' and '31' 
                 and YEAR(datefab)='" & CmB1.Text & "' 
                 group by MONTH(datefab),YEAR(datefab)
    )
    ,t2 as(
       select SUM(ISNULL(poids,0)) prod1,
            MONTH(datefab) mois,
            YEAR(datefab) an1 
            from etiquette 
       where DATEPART(day,datefab)='1' 
                 and YEAR(datefab)='" & CmB1.Text & "'
                 and DATEPART(hour,datefab)>= '0' 
                 and datepart(hour,datefab)<'6' 
       group by MONTH(datefab),YEAR(datefab)
    )
    ,t3 as(
       select SUM(isnull(poids,0)) prod2,
            MONTH(datefab)-1  mois2,
            YEAR(datefab) an2 
       from etiquette 
       where DATEPART(day,datefab)='1' 
            and YEAR(datefab)='" & CmB1.Text & "'
            and DATEPART(hour,datefab)>= '0' 
            and datepart(hour,datefab)<'6' 
       group by MONTH(datefab),YEAR(datefab)
    )
    ,t4 as(
       select  t1.mois1 moisprod,T1.AN ANNEE,
                 case when t1.prodm-t2.prod1+t3.prod2 is null then t1.prodm-t2.prod1 
                 else t1.prodm-t2.prod1+t3.prod2 
                 end as Production 
        from t1 
        Join t2 
            on t1.mois1=t2.mois and t1.an=T2.an1 
        left Join t3 
            on t1.mois1=t3.mois2 AND T1.an=T3.an2
    )
    ,
    t5 as(
       select year(datefab)-1 anf,
                 sum(isnull(poids,0)) tp,
                 month(datefab)+11 mf 
       from etiquette 
       where datepart(day,datefab)='1'
                 and year(datefab)='" & CmB1.Text & "'+1 
                 and datepart(hour,datefab)>'0'
                 and datepart(hour,datefab)<'6'
                 and month(datefab)='1'
        group by year(datefab),month(datefab)
    )
    ,t6 as(
       select t4.moisprod moisprod,
                 t4.annee ANNEE,
                 case when round((t4.Production+t5.tp)/1000,0) is null then round(t4.Production/1000,0) 
                 else round((t4.Production+t5.tp)/1000,0) 
                 end as Production 
       from t4 
       left join t5 
                 on t4.moisprod=t5.mf and t4.annee=t5.anf
    ) 
     
    select production,moisprod 
    from t6 
    where annee='" & CmB1.Text & "'"

    Je suis déjà étonné que cela puisse fonctionner sur un autre PC car déjà cette ligne (et surement d'autres) :
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    and year(datefab)='" & CmB1.Text & "'+1
    N'a pas de sens. Car si CmB1 contient bien une année, disons 2019 la requête donnerait :
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    and year(datefab)='2019'+1
    Je ne sais pas quel est votre SGBD mais en SQL serveur c'est une concaténation. Et même si ça ne l'est pas chez vous, ça n'a pas de sens de mettre des quotes pour des données numériques.

    Sinon, bête question, c'est bien du vb.Net? Pas plutôt du VB6?

  5. #5
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    je suis pas sur qu'adodb supporte le mot clé with

    personne n'utilise adodb en .net, il y a ado.net ...
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  6. #6
    Futur Membre du Club
    Homme Profil pro
    Responsable GPAO
    Inscrit en
    Avril 2007
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable GPAO
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 4
    Points : 9
    Points
    9
    Par défaut
    merci a vous deux,
    et merci pour Pol63
    problème résolu avec l'utilisation de ado.net.
    merci infiniment
    et pour qui cherche:
    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
     Public Sub Fill_DG()
     
            DGV.Enabled = False
            DGV.Rows.Clear()
            'chemincn est un fichier text qui comporte l'emplacement de ma base
            Dim cn As New SqlConnection(chemincn)
            Dim cmd As New SqlCommand("with t1 as(select sum(isnull(poids,0)) prodm,MONTH(datefab) mois1,YEAR(datefab) an from etiquette where DATEPART(day,datefab) between '1' and '31' and YEAR(datefab)=" & CmB1.Text & " group by MONTH(datefab),YEAR(datefab)),t2 as(select SUM(ISNULL(poids,0)) prod1,MONTH(datefab) mois,YEAR(datefab) an1 from etiquette where DATEPART(day,datefab)='1' and YEAR(datefab)=" & CmB1.Text & " and DATEPART(hour,datefab)>= '0' and datepart(hour,datefab)<'6' group by MONTH(datefab),YEAR(datefab)),t3 as(select SUM(isnull(poids,0)) prod2,MONTH(datefab)-1  mois2,YEAR(datefab) an2 from etiquette where DATEPART(day,datefab)='1' and YEAR(datefab)=" & CmB1.Text & " and DATEPART(hour,datefab)>= '0' and datepart(hour,datefab)<'6' group by MONTH(datefab),YEAR(datefab)),t4 as(select  t1.mois1 moisprod,T1.AN ANNEE,case when t1.prodm-t2.prod1+t3.prod2 is null then t1.prodm-t2.prod1 else t1.prodm-t2.prod1+t3.prod2 end as Production from t1 Join t2 on t1.mois1=t2.mois and t1.an=T2.an1 left Join t3 on t1.mois1=t3.mois2 AND T1.an=T3.an2),t5 as(select year(datefab)-1 anf,sum(isnull(poids,0)) tp,month(datefab)+11 mf from etiquette where datepart(day,datefab)='1'and year(datefab)=" & CmB1.Text & "+1 and datepart(hour,datefab)>'0'and datepart(hour,datefab)<'6'and month(datefab)='1'group by year(datefab),month(datefab)),t6 as(select t4.moisprod moisprod,t4.annee ANNEE,case when round((t4.Production+t5.tp)/1000,0) is null then round(t4.Production/1000,0) else round((t4.Production+t5.tp)/1000,0) end as Production from t4 left join t5 on t4.moisprod=t5.mf and t4.annee=t5.anf) select production,moisprod from t6 where annee=" & CmB1.Text & "", cn)
            Dim ds As New DataSet
            Dim da As New SqlDataAdapter(cmd)
            cn.Open()
            Dim rd As SqlDataReader = cmd.ExecuteReader
     
     
            If rd.HasRows Then
                While rd.Read
                    DGV.Rows.Add(rd(1), rd(0))
                End While
            End If
            rd.Close()
     
            DGV.Enabled = True
     
        End Sub

  7. #7
    Modérateur
    Avatar de Sankasssss
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2006
    Messages
    1 842
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 842
    Points : 4 232
    Points
    4 232
    Par défaut
    C'est une bonne chose que vous ayez changé pour ado.net

    Vous disiez dans le message supprimé :
    mais sur le pc principale qui comporte le base de donnée sql server il ne fonctionne plus.
    Fait donc bien attention, car comme je le disais précédemment, sur SQL serveur, ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    and year(datefab)='" & CmB1.Text & "'+1
    Donne ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    and year(datefab)='2019'+1
    Ce qui donne en fait ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    and year(datefab)='20191'
    Alors que je suis persuadé que vous vouliez :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    and year(datefab)='2020'
    Autre petite amélioration. Essayez d'utiliser les requêtes paramétrées : https://webman.developpez.com/articl...rameter/vbnet/

  8. #8
    Futur Membre du Club
    Homme Profil pro
    Responsable GPAO
    Inscrit en
    Avril 2007
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable GPAO
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 4
    Points : 9
    Points
    9
    Par défaut
    Merci pour votre aide, pour les cotes comme vous voyez j'ai déjà supprimé dans le nouveau code.
    pour l'utilisation des requêtes paramétrées je prendre cette remarque et je vais essayer merci.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Incorrect syntax near the keyword 'SELECT'.
    Par hounaida nou dans le forum Développement
    Réponses: 2
    Dernier message: 29/04/2019, 08h13
  2. [2012] Incorrect syntax near the keyword 'group'.
    Par SirIp dans le forum Développement
    Réponses: 1
    Dernier message: 07/02/2019, 15h14
  3. Incorrect syntax near the keyword 'as'
    Par samsso2006 dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 06/09/2013, 17h37
  4. Incorrect syntax near the keyword
    Par Trady dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 31/12/2012, 15h41
  5. [SSIS] [2K8] Incorrect syntax near the keyword 'MERGE'
    Par gassisprog dans le forum SSIS
    Réponses: 1
    Dernier message: 28/09/2009, 17h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo