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

C# Discussion :

[WinForm]Modification d'un appel d'une procédure stockée T/SQL - optimisation de code


Sujet :

C#

  1. #1
    Membre actif Avatar de stolx_10
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 374
    Points : 270
    Points
    270
    Par défaut [WinForm]Modification d'un appel d'une procédure stockée T/SQL - optimisation de code
    Bonjour

    J'ai actuellement un code fonctionnel qui appelle une procédure stockée écrite dans une class.
    Mais quand je lis le code, j'ai une impression d'usine à gaz, de bouilli, bref quelque chose de mal optimisé.

    J'aurai besoin d'une aide pour mieux réécrire mon code d'appel à la procédure stockée.

    Pour commencer voici la méthode appelante
    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
     
    //FLAgents = class form principale
    // DBG_LAgents = datagridview
    //DBS_LAgents = BindingSource
     
            //variables public dans ma class form
            public string APresents, APartis, AMatricule, ANom, ACarriere, ATypeCar = "", A_NomJeuneFille, AOrderBy = "", ACarSimple = "";
     
            private void FLAgents_Load(object sender, EventArgs e)
            {
                Cursor.Current = Cursors.WaitCursor;
     
                DBG_LAgents.DataSource = DBS_LAgents;
                Fill_DBG_LAgents(SQL_Liste());
     
                Cursor.Current = Cursors.Default;
            }
    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
    private void Fill_DBG_LAgents(string macommande)
            {
     
                GO_Init.Init_connexion(); //connexion à la base de doonées
     
                try
                {
     
                    OdbcCommand dataSQL = new OdbcCommand(macommande, GO_Init.conn);
     
                    OdbcDataReader read = dataSQL.ExecuteReader();
     
                    DataSet ds = new DataSet();
                    DataTable dt = new DataTable("Table1");
     
                    ds.Tables.Add(dt); //ajout du datatable dans le dataset
     
                    // je vide tout avant de remplir au cas où
                    dt.Clear();
                    ds.Tables[0].Clear();
                    DBG_LAgents.DataSource = null;
     
                    DBG_LAgents.AutoGenerateColumns = false;
                    DBG_LAgents.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
     
     
                    ds.Load(read, LoadOption.PreserveChanges, ds.Tables[0]); //chargement du dataset - ligne de code récupéré sur le net
     
                    Cursor.Current = Cursors.WaitCursor;
     
                    DBG_LAgents.SuspendLayout();
     
                    //Charge_BarreChargement(ds);
     
                    DBG_LAgents.DataSource = ds.Tables[0]; //remplissage de mon datagridview
                    DBG_LAgents.ResumeLayout();
     
                    DBG_LAgents.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
                    this.localite.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
     
                    Cursor.Current = Cursors.Default;
     
                    BE_Text1.Text = DBG_LAgents.RowCount.ToString() + " agent(s) affiché(s).";
     
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    GO_Init.conn.Close(); //fermeture de la connexion
                }
     
            }
    macommande est chargée par cette méthode :
    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
            public string SQL_Liste()
            {
     
     
                //Paramètres Présents ou non et Partis ou non ('1' ou '0') et ('1' ou '0')
                APresents = IN_Presents.Checked == true ? "1" : "0";
                APartis = IN_Partis.Checked == true ? "1" : "0";
     
                //Paramétres de Matricule ('0' ou 'Matricule') et Début de Nom ('0' ou "'Début de Nom'")
                if (MatNom == "")
                {
                    //Pas de restriction sur matricule ou début de nom
                    AMatricule = "0";
                    ANom = "0";
                }
                else
                {   
                    int resultParse = 0;
     
                    if (int.TryParse(MatNom.Trim(), out resultParse))
                    {
                        if ((MatNom.Trim().Substring(MatNom.Length - 1) != "0") && (MatNom.Trim().Length < 8))
                            MatNom = MatNom.Trim() + "0";
                        //'Restriction sur matricule
                        AMatricule = MatNom.Trim().PadLeft(8, '0');
                        ANom = "0";
                    }
                    else
                    {
                        AMatricule = "0";
                        ANom = MatNom.Trim();
                    }
                }
     
                //Paramètre : seulement les agents sans carrière ou non ('1' ou '0')
                ACarriere = IN_Carriere.Checked == true ? "1" : "0";
     
                //Paramètre type de carrière ('0', '1', '2', '3', '12', '13', '23', ou '9')
                if (IN_DoubleCarriere.Checked == true)
                    ATypeCar = "D";
                else
                {
                    if (B_SPPcheck && B_SPVcheck && B_ATScheck)
                        //tous
                        ATypeCar = "9";
                    else
                    {
                        if (!B_SPPcheck && !B_SPVcheck && !B_ATScheck)
                            //aucun
                            ATypeCar = "0";
                        else
                        {
                            if (B_SPPcheck && !B_SPVcheck && !B_ATScheck)
                                //SPP
                                ATypeCar = "1";
                            else
                            {
                                if (!B_SPPcheck && B_SPVcheck && !B_ATScheck)
                                    //SPV
                                    ATypeCar = "2";
                                else
                                {
                                    if (!B_SPPcheck && !B_SPVcheck && B_ATScheck)
                                        //ATS
                                        ATypeCar = "3";
                                    else
                                    {
                                        if (B_SPPcheck && B_SPVcheck && !B_ATScheck)
                                            //SPP & SPV
                                            ATypeCar = "12";
                                        else
                                        {
                                            if (B_SPPcheck && !B_SPVcheck && B_ATScheck)
                                                //SPP & ATS
                                                ATypeCar = "13";
                                            else
                                            {
                                                if (!B_SPPcheck && B_SPVcheck && B_ATScheck)
                                                    //SPV & ATS
                                                    ATypeCar = "23";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
     
                }
     
                //Paramètres de l'order by ( Exemple : "'order by ag.nom ASC ou DESC '" )
                int E_No_Col = 0;
                switch (E_No_Col)
                {
                    case 0:
                        AOrderBy = "'' Order by ag.matricule ASC ''";
                        break;
                    case 1:
                        AOrderBy = "";
                        break;
                    case 2:
                        AOrderBy = "";
                        break;
                    case 3:
                        AOrderBy = "";
                        break;
                    case 4:
                        AOrderBy = "";
                        break;
                }
     
                //Paramètre @CarSimple (carrière simple, O/N)
                if (IN_Carriere.Checked == true)
                    ACarSimple = "N";
                else
                {
                    if (IN_CarriereSimple.Checked == true)
                        ACarSimple = "O";
                    else
                        ACarSimple = "N";
                }
     
                //recherche sur le nom de jeune fille
                if (IN_NomJeuneFille.Checked == true)
                    A_NomJeuneFille = "O";
                else
                {
                    A_NomJeuneFille = "N";
                }
     
                // C'est cette partie qui m'intéresse
                SQL_PR_AGENTS_PREP_SELECTION pr_ag_prep_sel = new SQL_PR_AGENTS_PREP_SELECTION(
                    0, "MABASEDEDONNEES", "APPLI", "MOI", "0",
                    APresents, APartis, AMatricule, ANom, ACarriere, ATypeCar, AOrderBy, GO_Init.GA_Structure,
                    "", "", ACarSimple, A_NomJeuneFille);
     
                return pr_ag_prep_sel.req_sql; // car la méthode doit retourner un string pour la variable macommande
     
            } // fin SQL_Liste
    et enfin ma class externe à ma forme appelant la procédure stockée
    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
    using System;
     
    namespace MONAPPLI.Classes
    {
            public class SQL_PR_AGENTS_PREP_SELECTION 
            {
                public string req_sql;
     
                public SQL_PR_AGENTS_PREP_SELECTION(int B_Edit, string A_BaseSOC, string A_Module
                                         , string A_User, string Actif, string Presents
                                         , string Partisg, string Matricule, string Nom
                                         , string Car, string TypeCar, string OrderBy, string restrict_centre
                                         , string GMFI_HABI, string Date_Ref, string CarSimple
                                         , string NomJeuneFille)
                {
                    req_sql = "EXEC PR_AGENTS_PREP_SELECTION ";
                    req_sql = req_sql + (B_Edit == 0 ? "0" : "1") ;
                    req_sql = req_sql + ",'" + A_BaseSOC.Trim() + "' ";
                    req_sql = req_sql + ",'" + A_Module.Trim() + "' ";
                    req_sql = req_sql + ",'" + A_User.Trim() + "' ";
                    req_sql = req_sql + ",'" + Actif.Trim() + "' ";
                    req_sql = req_sql + ",'" + Presents.Trim() + "' ";
                    req_sql = req_sql + ",'" + Partisg.Trim() + "' ";
                    req_sql = req_sql + ",'" + Matricule.Trim() + "' ";
                    req_sql = req_sql + ",'" + Nom.Trim() + "' ";
                    req_sql = req_sql + ",'" + Car.Trim() + "' ";
                    req_sql = req_sql + ",'" + TypeCar.Trim() + "' ";
                    req_sql = req_sql + ",'" + OrderBy.Trim() + "' ";
                    req_sql = req_sql + ",'" + restrict_centre.Trim() + "' ";
                    req_sql = req_sql + ",'" + GMFI_HABI.Trim() + "' ";
                    req_sql = req_sql + ",'" + Date_Ref.Trim() + "' ";
                    req_sql = req_sql + ",'" + CarSimple.Trim() + "' ";
                    req_sql = req_sql + ",'" + NomJeuneFille.Trim() + "' ";
     
                }
     
     
            }
     
    }
    Le code étant fonctionnel, est ce pour vous une usine à gaz également ? si oui, comment le changer ?

  2. #2
    Membre actif Avatar de stolx_10
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 374
    Points : 270
    Points
    270
    Par défaut
    personne n'a d'idées ?

    sinon, si le code convient comme il est, je ne m'attarderai pas sur le sujet

    merci

  3. #3
    Membre émérite Avatar de Guulh
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    2 160
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2007
    Messages : 2 160
    Points : 2 925
    Points
    2 925
    Par défaut
    Salut,

    ton code pourrait être très simplifié; je t'invite d'abord à jeter un oeil à ce tuto, qui décrit notamment comment utiliser des requêtes paramétrées plutôt que d'envoyer une seule chaîne concaténée à la base.
    ಠ_ಠ

  4. #4
    Membre actif Avatar de stolx_10
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 374
    Points : 270
    Points
    270
    Par défaut
    Justement c'est un peu à ça que je pensais, passer par des requêtes paramétrées, mais dans mon cas, je suis comme qui dirait un peu perdu.

    En fait je voudrais juste savoir quelle partie je dois toucher, si ce n'est juste la class externe à modifier, je pourrais m'en sortir, mais si je dois toucher le reste, j'aimerais bien un peu d'aides

  5. #5
    Membre émérite Avatar de Guulh
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    2 160
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2007
    Messages : 2 160
    Points : 2 925
    Points
    2 925
    Par défaut
    Hello,

    dans le lien que j'ai mis, regarde la partie sur les requêtes paramétrées.
    L'idée, c'est de ne pas parler avec la base que via l'envoi d'une grosse chaîne de caractère, mais par l'envoi du nom de la proc stock + de la liste des valeurs des paramètres.
    Par exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    private void button1_Click(object sender, EventArgs e) {
      using (SqlConnection con = new SqlConnection(dc.Con)) {
        using (SqlCommand cmd = new SqlCommand("sp_Add_contact", con)) {
          cmd.CommandType = CommandType.StoredProcedure;
     
          cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName.Text;
          cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = txtLastName.Text;
     
          con.Open();
          cmd.ExecuteNonQuery();
        }
      }
    }
    ಠ_ಠ

  6. #6
    Membre actif Avatar de stolx_10
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 374
    Points : 270
    Points
    270
    Par défaut
    Merci

    J'avais déjà trouvé cette syntaxe avant de me lancer dans ce que j'ai écrit plus haut.
    Seulement, je n'arrivais à adapter cette syntaxe avec la syntaxe que j'ai reprise d'un code VB5 (j'essaie de réécrire une appli entièrement depuis du code VB5 vers c#)

    VB5
    Code VB : 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
    Private Property Get SQL_PR_AGENTS_PREP_SELECTION(ByVal B_Edit As Boolean, ByVal A_BaseSOC As String, ByVal A_Module As String _
                                                , ByVal A_User As String, ByVal Actif As String, ByVal Presents As String _
                                                , ByVal Partis As String, ByVal Matricule As String, ByVal Nom As String _
                                                , ByVal Car As String, ByVal TypeCar As String, ByVal OrderBy As String, ByVal restrict_centre As String _
                                                , ByVal GMFI_HABI As String, ByVal Date_Ref As String, ByVal CarSimple As String _
                                                , ByVal NomJeuneFille As String)
     
        Dim a_sql As String
     
        If A_BaseSOC = "" Then A_BaseSOC = GO_Table.Dossier
        If A_Module = "" Then A_Module = GO_Nom_module
        If A_User = "" Then A_User = GO_Utilisateur
     
        a_sql = "EXEC " & GO_Table.Dossier & "..PR_AGENTS_PREP_SELECTION" & IIf(GBTest, "_TEST", "") & ""
        a_sql = a_sql & IIf(B_Edit, "'1'", "'0'")
        a_sql = a_sql & ",'" & Trim(A_BaseSOC) & "' "
        a_sql = a_sql & ",'" & Trim(A_Module) & "' "
        a_sql = a_sql & ",'" & Trim(A_User) & "' "
        a_sql = a_sql & ",'" & Trim(Actif) & "' "
        a_sql = a_sql & ",'" & Trim(Presents) & "' "
        a_sql = a_sql & ",'" & Trim(Partis) & "' "
        a_sql = a_sql & ",'" & Trim(Matricule) & "' "
        a_sql = a_sql & ",'" & Trim(Nom) & "' "
        a_sql = a_sql & ",'" & Trim(Car) & "' "
        a_sql = a_sql & ",'" & Trim(TypeCar) & "' "
        a_sql = a_sql & ",'" & Trim(OrderBy) & "' "
        a_sql = a_sql & ",'" & Trim(restrict_centre) & "' "
        a_sql = a_sql & ",'" & Trim(GMFI_HABI) & "' "
        a_sql = a_sql & ",'" & Trim(Date_Ref) & "' "
        a_sql = a_sql & ",'" & Trim(CarSimple) & "' "
        'MSA 200706
        a_sql = a_sql & ",'" & Trim(NomJeuneFille) & "' "
     
        SQL_PR_AGENTS_PREP_SELECTION = a_sql
     
    End Property

    Code VB : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Private Property Get SQL_Liste() As String
     
      'paramétres et conditions bla bla
       '[...]
     
        a_sql = SQL_PR_AGENTS_PREP_SELECTION(0, GO_Table.Dossier, GO_Nom_module, GO_Utilisateur, _
                                            "0", APresents, APartis, AMatricule, ANom, ACarriere, ATypeCar, AOrderBy, _
                                            GA_Structure, GA_Habillement, GA_Date, ACarSimple, A_NomJeuneFille)
     
        SQL_Liste = a_sql
    End Property

    En fait j'ai essayé de reprendre en C# quasiment mots pour mots, mais je coinçais à cause des méthodes écrites en "Private property get".

    Donc j'ai fait au mieux, mais si je dois effectivement reprendre la syntaxe des procédures stockées en requêtes paramétrées, je vais m'y coller.

  7. #7
    Membre actif Avatar de stolx_10
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 374
    Points : 270
    Points
    270
    Par défaut
    Bonjour

    j'ai donc fait des modifications dans mon prog pour lancer ma procédure en mode paramétré, mais dès que je veux Fill mon dataset à l'adaptater, il me sort qu'il manque le paramètre @B_Edit (le 1er paramètre)
    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
                        GO_Init.Init_connexion();
     
                        OdbcCommand dataSQL = new OdbcCommand("PR_AGENTS_PREP_SELECTION", GO_Init.conn);
     
                        dataSQL.CommandType = CommandType.StoredProcedure;
                        dataSQL.Parameters.Add("@B_Edit", SqlDbType.Char).Value = '0'; // ou "0" (zéro) ne marche pas non plus
                        dataSQL.Parameters.Add("@BaseSOC", SqlDbType.VarChar).Value = "ma_base";
                        dataSQL.Parameters.Add("@Module", SqlDbType.VarChar).Value = "mon_appli";
                        dataSQL.Parameters.Add("@User", SqlDbType.VarChar).Value = "MOI";
                        dataSQL.Parameters.Add("@Actif", SqlDbType.VarChar).Value = "0";
                        dataSQL.Parameters.Add("@Presents", SqlDbType.VarChar).Value = APresents;
                        dataSQL.Parameters.Add("@Partis", SqlDbType.VarChar).Value = APartis;
                        dataSQL.Parameters.Add("@Matricule", SqlDbType.VarChar).Value = AMatricule;
                        dataSQL.Parameters.Add("@Nom", SqlDbType.VarChar).Value = ANom;
                        dataSQL.Parameters.Add("@Car", SqlDbType.VarChar).Value = ACarriere;
                        dataSQL.Parameters.Add("@TypeCar", SqlDbType.VarChar).Value = ATypeCar;
                        dataSQL.Parameters.Add("@OrderBy", SqlDbType.VarChar).Value = AOrderBy;
                        dataSQL.Parameters.Add("@restrict_centre", SqlDbType.VarChar).Value = GO_Init.GA_Structure;
                        dataSQL.Parameters.Add("@GMFI_HABI", SqlDbType.VarChar).Value = "";
                        dataSQL.Parameters.Add("@Date_Ref", SqlDbType.VarChar).Value = "";
                        dataSQL.Parameters.Add("@CarSimple", SqlDbType.VarChar).Value = ACarSimple;
                        dataSQL.Parameters.Add("@BNomJF", SqlDbType.VarChar).Value = A_NomJeuneFille;
     
                        OdbcDataAdapter Dta = new OdbcDataAdapter();
     
                        Dta.SelectCommand = dataSQL; 
     
                        DataSet ds = new DataSet();
     
                        DBG_LAgents.DataSource = null;
     
                        DBG_LAgents.AutoGenerateColumns = false;
     
                        DBG_LAgents.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
     
     
                        Dta.Fill(ds);
    ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]La procédure ou fonction 'PR_AGENTS_PREP_SELECTION' attend le paramètre '@B_Edit', qui n'a pas été fourni.

    voici les paramètres de la procédure dans SQL
    Nom : proc_stock_param.jpg
Affichages : 268
Taille : 71,9 Ko




    EDIT : j'ai changé les SqlDbType en OdbcType, mais j'ai toujours la même erreur

  8. #8
    Membre actif Avatar de stolx_10
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 374
    Points : 270
    Points
    270
    Par défaut
    pareil avec using :

    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
                        using (OdbcCommand dataSQL = new OdbcCommand("PR_AGENTS_PREP_SELECTION", GO_Init.conn))
                        {
                            dataSQL.CommandType = CommandType.StoredProcedure;
     
                            dataSQL.Parameters.Add("@B_Edit", OdbcType.Char, 1).Value = "0";
                            dataSQL.Parameters.Add("@BaseSOC", OdbcType.VarChar).Value = "DDSIS520001";
                            dataSQL.Parameters.Add("@module", OdbcType.VarChar).Value = "CRSS";
                            dataSQL.Parameters.Add("@User", OdbcType.VarChar).Value = "SIS";
                            dataSQL.Parameters.Add("@Actif", OdbcType.VarChar).Value = "0";
                            dataSQL.Parameters.Add("@Presents", OdbcType.VarChar).Value = APresents;
                            dataSQL.Parameters.Add("@Partis", OdbcType.VarChar).Value = APartis;
                            dataSQL.Parameters.Add("@Matricule", OdbcType.VarChar).Value = AMatricule;
                            dataSQL.Parameters.Add("@Nom", OdbcType.VarChar).Value = ANom;
                            dataSQL.Parameters.Add("@Car", OdbcType.VarChar).Value = ACarriere;
                            dataSQL.Parameters.Add("@TypeCar", OdbcType.VarChar).Value = ATypeCar;
                            dataSQL.Parameters.Add("@OrderBy", OdbcType.VarChar).Value = AOrderBy;
                            dataSQL.Parameters.Add("@restrict_centre", OdbcType.VarChar).Value = GO_Init.GA_Structure;
                            dataSQL.Parameters.Add("@GMFI_HABI", OdbcType.VarChar).Value = "";
                            dataSQL.Parameters.Add("@Date_Ref", OdbcType.VarChar).Value = "";
                            dataSQL.Parameters.Add("@CarSimple", OdbcType.VarChar).Value = ACarSimple;
                            dataSQL.Parameters.Add("@BNomJF", OdbcType.VarChar).Value = A_NomJeuneFille;
     
                            OdbcDataAdapter Dta = new OdbcDataAdapter(dataSQL);
                            DataSet ds = new DataSet();
     
                            DBG_LAgents.DataSource = null;
     
                            DBG_LAgents.AutoGenerateColumns = false;
     
                            DBG_LAgents.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
     
     
                            Dta.Fill(ds);
     
                            Cursor.Current = Cursors.WaitCursor;
     
                            DBG_LAgents.SuspendLayout();
     
                            Charge_BarreChargement(ds);
     
                            DBG_LAgents.DataSource = ds;
     
                            DBG_LAgents.ResumeLayout();
     
                            DBG_LAgents.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
                            this.localite.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
     
                            Cursor.Current = Cursors.Default;
     
                            BE_Text1.Text = DBG_LAgents.RowCount.ToString() + " agent(s) affiché(s).";
                        }

  9. #9
    Membre actif Avatar de stolx_10
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    374
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 374
    Points : 270
    Points
    270
    Par défaut
    J'ai réussi

    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
                       GO_Init.Init_connexion();
     
                        OdbcCommand dataSQL = new OdbcCommand("{call PR_AGENTS_PREP_SELECTION;1(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}", GO_Init.conn))
     
                        dataSQL.Parameters.Add("@B_Edit", OdbcType.Char).Value = "0";
                        dataSQL.Parameters.Add("@BaseSOC", OdbcType.VarChar).Value = "DDSIS520001";
                        dataSQL.Parameters.Add("@module", OdbcType.VarChar).Value = "CRSS";
                        dataSQL.Parameters.Add("@User", OdbcType.VarChar).Value = "SIS";
                        dataSQL.Parameters.Add("@Actif", OdbcType.VarChar).Value = "0";
                        dataSQL.Parameters.Add("@Presents", OdbcType.VarChar).Value = APresents;
                        dataSQL.Parameters.Add("@Partis", OdbcType.VarChar).Value = APartis;
                        dataSQL.Parameters.Add("@Matricule", OdbcType.VarChar).Value = AMatricule;
                        dataSQL.Parameters.Add("@Nom", OdbcType.VarChar).Value = ANom;
                        dataSQL.Parameters.Add("@Car", OdbcType.VarChar).Value = ACarriere;
                        dataSQL.Parameters.Add("@TypeCar", OdbcType.VarChar).Value = ATypeCar;
                        dataSQL.Parameters.Add("@OrderBy", OdbcType.VarChar).Value = AOrderBy;
                        dataSQL.Parameters.Add("@restrict_centre", OdbcType.VarChar).Value = GO_Init.GA_Structure;
                        dataSQL.Parameters.Add("@GMFI_HABI", OdbcType.VarChar).Value = "";
                        dataSQL.Parameters.Add("@Date_Ref", OdbcType.VarChar).Value = "";
                        dataSQL.Parameters.Add("@CarSimple", OdbcType.VarChar).Value = ACarSimple;
                        dataSQL.Parameters.Add("@BNomJF", OdbcType.VarChar).Value = A_NomJeuneFille;
     
                        dataSQL.CommandType = CommandType.StoredProcedure;
     
                        DataSet ds = new DataSet();
                        DataTable dt = new DataTable("Table1");
     
                        OdbcDataReader read = dataSQL.ExecuteReader();
     
                        ds.Tables.Add(dt);
     
                        dt.Clear();
                        ds.Tables[0].Clear();
                        DBG_LAgents.DataSource = null;
     
                        ds.Load(read, LoadOption.PreserveChanges, ds.Tables[0]);
     
     
     
                        Cursor.Current = Cursors.WaitCursor;
     
                        DBG_LAgents.DataSource = null;
     
                        DBG_LAgents.AutoGenerateColumns = false;
     
                        DBG_LAgents.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
     
                        DBG_LAgents.SuspendLayout();
     
                        Charge_BarreChargement(ds);
     
                        DBG_LAgents.DataSource = ds.Tables[0]; 
     
                        DBG_LAgents.ResumeLayout();
     
                        DBG_LAgents.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
                        this.localite.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
     
                        Cursor.Current = Cursors.Default;
     
                        BE_Text1.Text = DBG_LAgents.RowCount.ToString() + " agent(s) affiché(s).";
    Via odbc, il ne faut pas seulement appeler la procédure par son nom, mais également passer les paramètres en ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    OdbcCommand dataSQL = new OdbcCommand("{call PR_AGENTS_PREP_SELECTION;1(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}", GO_Init.conn))
    le ;1 présent dans ma chaine correspond à la valeur de retour de la procédure stockée (je ne suis pas obligé de le mettre cela dit)

    Mais pourquoi tant de haine !

    Merci tout de même aux personnes m'ayant lu et répondu

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

Discussions similaires

  1. Appel d'une procédure stockée de SQL Server
    Par IRAD dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 28/04/2008, 12h36
  2. [c#] Appel d'une procédure stockée Record
    Par lapartdombre dans le forum Accès aux données
    Réponses: 4
    Dernier message: 02/08/2007, 17h20
  3. Appel d'une procédure stockée sous VB 6
    Par Polux000 dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 11/01/2006, 09h21
  4. Réponses: 2
    Dernier message: 10/12/2004, 15h43
  5. Appel d'une procédure stockée par un vbscript
    Par NicoNours dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 08/10/2004, 13h53

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