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 :

requête sql erreur de syntaxe


Sujet :

VB.NET

  1. #1
    Membre du Club
    Inscrit en
    Décembre 2006
    Messages
    158
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 158
    Points : 56
    Points
    56
    Par défaut requête sql erreur de syntaxe
    Bonjour à tous,
    voilà j'ai un petit problème, lorsque j'essaie de d'exécuter mon application je reçois le message d'erreur suivant: Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'where'.

    Quelqu'un pourrait-il jeter un coup d'oeil svp?
    Bien à vous.
    Voici ma requête:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    Sub Button1_Click(sender As Object, e As EventArgs)
     
    Dim Sql As String
        Sql = "INSERT INTO Servers (Reboot) VALUES ('" & CheckReboot(TextBox1.Text) & "') where Ip = '" & TextBox1.Text & "'"
    SQLExecuteQueryConnect(Sql, SqlDataSourceControl1.ConnectionString)
     
    End Sub

  2. #2
    Membre éprouvé Avatar de obito
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2008
    Messages
    773
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Janvier 2008
    Messages : 773
    Points : 948
    Points
    948
    Par défaut
    Bonjour ! Pourquoi as-tu un where pour une insertion?

    Dans un INSERT y a pas à mettre de WHERE

  3. #3
    Membre du Club
    Inscrit en
    Décembre 2006
    Messages
    158
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 158
    Points : 56
    Points
    56
    Par défaut
    Bonjour,
    j'ai mis un where car au départ j'avait un update mais le problème c'est que je dois clicker 2 fois sur le bouton "update" pour que la mise à jour ce fasse.
    En gros il ne fait pas la mise à jour au premier click ce qui est un peut gênant. Donc je me suis dit que je pourrait faire un INSERT INTO avec la clause where pour qu'il écrase la valeur précédente par la nouvelle issue du insert.

  4. #4
    Membre éprouvé Avatar de obito
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2008
    Messages
    773
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Janvier 2008
    Messages : 773
    Points : 948
    Points
    948
    Par défaut
    TU dis vouloir écraser le valeur précédente avoir un INSERT. Mais alors quoi de mieux qu'un UPDATE plutôt?

    Et pour l'histoire du double click je peux pas trop voir vu que j'ai pas de code mais sur un click ca devrait faire un update non?

    Et dans le pire des cas tu fais deux updates

  5. #5
    Membre du Club
    Inscrit en
    Décembre 2006
    Messages
    158
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 158
    Points : 56
    Points
    56
    Par défaut
    je peux te montrer mon code si tu veux.

    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
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
     
    <%@ Page Language="VB" %>
    <%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
    <%@ import Namespace="System.Data" %>
    <%@ import Namespace="System.Data.SqlClient" %>
    <%@ import Namespace="System.Web.Mail" %>
    <%@ import Namespace="System.IO" %>
    <%@ import Namespace="System.DirectoryServices" %>
    <%@ import Namespace="System.Configuration" %>
    <%@ import Namespace="System.Net" %>
    <%@ import Namespace="System" %>
    <%@ import Namespace="System.Net.DNS" %>
    <%@ import Namespace="System.ComponentModel" %>
    <%@ import Namespace="System.Management" %>
    <%@ import Namespace="System.Runtime.InteropServices" %>
    <%@ import Namespace="System" %>
    <%@ import Namespace="ActiveDs" %>
    <%@ import Namespace="System.Text" %>
    <%@ import Namespace="System.Net.NetworkInformation" %>
    <%@ import Namespace="System.Net.Sockets" %>
    <script runat="server">
     
        ' Gestion des users
     
        '
        Sub Page_Load()
     
     
                     Dim Ldap As DirectoryEntry = New DirectoryEntry("LDAP://scoot.local", "toto", "toto")
                     Dim searcher As DirectorySearcher = New DirectorySearcher(Ldap)
                     searcher.Filter = "(objectClass=computer)"
                     Dim DirEntry As DirectoryEntry
                     Dim nom As String
                     Dim OsVersion As String
                     Dim Os As String
                     Dim ServicePack As String
                     Dim Ip As String
                     Dim largeInteger As Object
                     Dim lastLoggedOnDate As Date
                     Dim reboot As Date
                     Dim rebootTime As Object
     
                     SqlDataSourceControl1.ConnectionString="server='(local)'; trusted_connection=true; database='pspintranet'"
                     SqlDataSourceControl1.SelectCommand="Select * from Servers where OsName not like '%Server%'"
     
                      MxDataGrid1.DataBind()
     
                     End Sub
     
     
                 Function SQLExecuteQueryConnect(ByVal sqlQuery As String, sqlConnect as String) As String
     
                   Dim a As String
                 ' CREER LA CONNEXION
                   Dim objConnect As New SqlConnection(sqlConnect)
                   objConnect.Open()
     
                 ' CREER LA COMMANDE
                   Dim objCommand As New SqlCommand(sqlQuery, objConnect)
                 ' EXECUTER LA COMMANDE
                   a = objCommand.ExecuteNonQuery()
                   Return a
     
                 End Function
     
                 'Ici ce fait l'update
     
        Sub Button1_Click(sender As Object, e As EventArgs)
     
        Dim Sql As String
        'Sql = "INSERT INTO Servers (Reboot) VALUES ('" & CheckReboot(TextBox1.Text) & "') where Ip = '" & TextBox1.Text & "'"
        Sql = "UPDATE Servers SET Reboot = '" & CheckReboot(TextBox1.Text) & "' where Ip = '" & TextBox1.Text & "'"
        SQLExecuteQueryConnect(Sql, SqlDataSourceControl1.ConnectionString)
     
     
        End Sub
     
     
        Function CheckReboot(ipadress as String)
     
            Dim co As ConnectionOptions = New ConnectionOptions()
            Dim i As integer
            Dim strDate as String
            Dim TestConnection As Boolean
     
     
            'Dim Ip  As String
            'Ip = "192.168.1.170"
     
     
            With co
                .Impersonation = System.Management.ImpersonationLevel.Impersonate
                '* Use next line for XP
                .Authentication = System.Management.AuthenticationLevel.Packet
                '* Use next line for Win prior XP
                '.Authentication = System.Management.AuthenticationLevel.Connect
            End With
     
     
     
            co.Username = "toto"
            co.Password = "toto"
     
     
     
     
     
            Dim theScope As New ManagementScope("\\" & ipadress & "\root\cimv2",co)
     
     
     
            Dim theQuery As New System.Management.ObjectQuery("SELECT * From Win32_OperatingSystem ")
            Dim theSearcher As New ManagementObjectSearcher(theScope, theQuery)
     
            Try
     
            Dim theCollectionOfResults As ManagementObjectCollection = theSearcher.Get()
     
     
     
     
     
     
     
     
                    For Each currentResult As ManagementObject In theCollectionOfResults
                        strDate =  Left(currentResult("LastBootUpTime").ToString(),8)
                        Next
     
                        Catch com_ex As System.Runtime.InteropServices.COMException When com_ex.ErrorCode = &H800706BA
                        'Response.write("Machines are unvailable:" & ipadress &"It may be off line or the firewallsettings are preventing the connection")
     
                        Catch ua_ex As System.UnauthorizedAccessException
                       ' Response.write("The Remote PC refused the connection This is most likely due to a permissions issue.")
                        'Catch wmi_ex As Exception When wmi_ex.Exception = Management.ManagementStatus.AccessDenied
                        'Response.write("You do not have sufficient privileges on the remote PC:" & ipadress)
                        Catch ex As Exception
                         If IsNothing(ex.InnerException) Then
                         Response.write("Could not get initial data")
                         Else
                         Response.write("Could not get initial data:" & ex.InnerException.Message)
                         End if
                         End Try
                         return strDate
     
                         End Function
     
     
    </script>
    <html>
    <head>
    </head>
    <body>
        <form runat="server">
            <p>
                <wmx:SqlDataSourceControl id="SqlDataSourceControl1" runat="server" UpdateCommand="" DeleteCommand=""></wmx:SqlDataSourceControl>
                <wmx:MxDataGrid id="MxDataGrid1" runat="server" BorderStyle="None" BorderWidth="1px" BorderColor="#CCCCCC" BackColor="White" DataMember="Servers" DataSourceControlID="SqlDataSourceControl1" DataKeyField="nom_id" CellPadding="3" AllowSorting="True" AllowPaging="True">
                    <FooterStyle backcolor="White" forecolor="#000066"></FooterStyle>
                    <HeaderStyle backcolor="#006699" font-bold="True" forecolor="White"></HeaderStyle>
                    <ItemStyle forecolor="#000066"></ItemStyle>
                    <PagerStyle mode="NumericPages" horizontalalign="Center" backcolor="White" forecolor="#000066"></PagerStyle>
                    <SelectedItemStyle backcolor="#669999" font-bold="True" forecolor="White"></SelectedItemStyle>
                </wmx:MxDataGrid>
            </p>
            <p>
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
            </p>
            <p>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Update"></asp:Button>
            </p>
            <!-- Insert content here -->
        </form>
    </body>
    </html>
    Bien à toi.

  6. #6
    Membre du Club
    Inscrit en
    Décembre 2006
    Messages
    158
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 158
    Points : 56
    Points
    56
    Par défaut
    Merci, affaire résolue

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

Discussions similaires

  1. [SQL] Requête SQL erreur de syntaxe
    Par helopme_69 dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 05/01/2008, 21h51
  2. [SQL] Erreur de syntaxe sur ma requête UPDATE
    Par webasso dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 18/09/2007, 14h55
  3. [Requête/SQL]Erreur Syntaxe Access
    Par LAETIAZ dans le forum Requêtes et SQL.
    Réponses: 4
    Dernier message: 23/04/2007, 12h29
  4. [sql] erreur de syntaxe
    Par cmoa59 dans le forum JDBC
    Réponses: 14
    Dernier message: 03/05/2005, 11h41
  5. PHP SQL =>erreur de syntaxe (operateur absent)
    Par snipes dans le forum Langage SQL
    Réponses: 3
    Dernier message: 23/02/2005, 14h09

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