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

ASP.NET Discussion :

requete sql UPDATE sqldatasource


Sujet :

ASP.NET

  1. #1
    Membre extrêmement actif Avatar de mapmip
    Profil pro
    ulla
    Inscrit en
    Juillet 2006
    Messages
    1 326
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : ulla

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 326
    Par défaut requete sql UPDATE sqldatasource
    Bonjour,
    j'ai un gridview connecté à un sqldatasource (Base postgresql),

    comment faire pour savoir quelle est la requete update envoyée à la base pour execution?

    merci d'avance

  2. #2
    Membre Expert
    Avatar de Nicolas Esprit
    Homme Profil pro
    Consultant en technologies
    Inscrit en
    Février 2010
    Messages
    1 467
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Consultant en technologies
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2010
    Messages : 1 467
    Par défaut
    Bonjour,

    C'est à toi de la définir en fait. cf : MSDN

    En espérant t'avoir aidé.

  3. #3
    Membre extrêmement actif Avatar de mapmip
    Profil pro
    ulla
    Inscrit en
    Juillet 2006
    Messages
    1 326
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : ulla

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 326
    Par défaut
    Citation Envoyé par Nicolas Esprit Voir le message
    Bonjour,

    C'est à toi de la définir en fait. cf : MSDN

    En espérant t'avoir aidé.
    Oui , c'est ce qui est fait, mais existe t il un moyen d'intercepter la chaine de caractere sql qui sera envoyé à la base ?

  4. #4
    Membre Expert
    Avatar de Nicolas Esprit
    Homme Profil pro
    Consultant en technologies
    Inscrit en
    Février 2010
    Messages
    1 467
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Consultant en technologies
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2010
    Messages : 1 467
    Par défaut
    Oui biensûr, en utilisant les events de la DataSource. Exemple repris de MSDN :

    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
    <%@Page  Language="C#" %>
    <%@Import Namespace="System.Data" %>
    <%@Import Namespace="System.Data.Common" %>
    <%@Import Namespace="System.Data.SqlClient" %>
    <%@Import Namespace="System.Diagnostics" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <script runat="server">
     
     private void On_Click(Object source, EventArgs e) {    
        SqlDataSource1.Update();
     }
     
     private void OnSqlUpdating(Object source, SqlDataSourceCommandEventArgs e) {
        DbCommand command = e.Command;
        DbConnection cx  = command.Connection;    
        cx.Open();    
        DbTransaction tx = cx.BeginTransaction();
        command.Transaction = tx;
     }
     
     private void OnSqlUpdated(Object source, SqlDataSourceStatusEventArgs e) {
        DbCommand command = e.Command;
        DbTransaction tx = command.Transaction;
     
        // In this code example the OtherProcessSucceeded variable represents
        // the outcome of some other process that occurs whenever the data is 
        // updated, and must succeed for the data change to be committed. For 
        // simplicity, we set this value to true. 
        bool OtherProcessSucceeded = true;
     
        if (OtherProcessSucceeded) {
            tx.Commit();
            Label2.Text="The record was updated successfully!";
        }
        else {
            tx.Rollback();
            Label2.Text="The record was not updated.";
        }
     }
     
    </script>
     
    <html xmlns="http://www.w3.org/1999/xhtml" >
      <head runat="server">
        <title>ASP.NET Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
          <asp:SqlDataSource
              id="SqlDataSource1"
              runat="server"
              ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
              SelectCommand="SELECT EmployeeID, LastName, Address FROM Employees"
              UpdateCommand="UPDATE Employees SET Address=@Address WHERE EmployeeID=@EmployeeID"
              OnUpdating="OnSqlUpdating"
              OnUpdated ="OnSqlUpdated">
              <UpdateParameters>
                  <asp:ControlParameter Name="Address" ControlId="TextBox1" PropertyName="Text"/>
                  <asp:ControlParameter Name="EmployeeID" ControlId="DropDownList1" PropertyName="SelectedValue"/>
              </UpdateParameters>
          </asp:SqlDataSource>
     
          <asp:DropDownList
              id="DropDownList1"
              runat="server"
              DataTextField="LastName"
              DataValueField="EmployeeID"
              DataSourceID="SqlDataSource1">
          </asp:DropDownList>
     
          <br />
          <asp:Label id="Label1" runat="server" Text="Enter a new address for the selected user."
            AssociatedControlID="TextBox1" />
          <asp:TextBox id="TextBox1" runat="server" />
          <asp:Button id="Submit" runat="server" Text="Submit" OnClick="On_Click" />
     
          <br /><asp:Label id="Label2" runat="server" Text="" />
     
        </form>
      </body>
    </html>
    En espérant t'avoir aidé.

Discussions similaires

  1. requete SQL update base access
    Par samtheh dans le forum VBA Access
    Réponses: 6
    Dernier message: 01/06/2007, 13h06
  2. requete sql update
    Par neuneu1 dans le forum Bases de données
    Réponses: 18
    Dernier message: 20/04/2007, 09h56
  3. requete sql update/insert
    Par snetechen dans le forum Langage SQL
    Réponses: 4
    Dernier message: 18/04/2007, 17h29
  4. [VBA][SQL] code pour requete sql update en vba
    Par titocv723 dans le forum Requêtes et SQL.
    Réponses: 14
    Dernier message: 24/10/2006, 17h45
  5. Parametres listbox requete SQL & "updateable query" erreur
    Par haibane dans le forum Requêtes et SQL.
    Réponses: 10
    Dernier message: 01/09/2006, 11h52

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