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 :

Utiliser plusieurs tables dans une application 3 tiers sous c# [Débutant]


Sujet :

C#

  1. #1
    Membre régulier
    Inscrit en
    Janvier 2007
    Messages
    219
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 219
    Points : 76
    Points
    76
    Par défaut Utiliser plusieurs tables dans une application 3 tiers sous c#
    Bonjour
    Je suis nouveau dans C#
    Je suis un projet pour la gestion de projets en 3tiers, j’ai créé les tables sous MSSQL SERVER 2008
    Et j’ai crée les 3 couches dan C#
    BAL
    BEL
    Et DAL

    J’ai créé mon premier formulaire Windows form pour la saisie des utilisateurs, l’insertion marche pour les utilisateurs.
    Lorsque je crée mon 2eme formulaire pour saisie des profils, il m’affiche une erreur d’exception non gérer.

    J’aimerai avoir une explication sur la gestion multitâble dans une application 3 tiers sous c#
    Nom : erreyr.jpg
Affichages : 465
Taille : 148,1 Ko

  2. #2
    Membre actif
    Homme Profil pro
    Autodidacte
    Inscrit en
    Mars 2016
    Messages
    154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Brazzaville

    Informations professionnelles :
    Activité : Autodidacte
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2016
    Messages : 154
    Points : 268
    Points
    268
    Par défaut
    Bonjour,
    pourrais tu publier la cmd que tu essayes d'exécuter. je crois l'erreur devrais venir de là ?

  3. #3
    Membre régulier
    Inscrit en
    Janvier 2007
    Messages
    219
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 219
    Points : 76
    Points
    76
    Par défaut
    Bonjour
    je vous envoie la commande
    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 System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;
     
    namespace DAL
    {
        public class Dbconnection
        {
            public SqlConnection con = new SqlConnection ("Data Source=ABORE-PC\\SQLEXPRESS;Initial Catalog=DATAPROJ;Integrated Security=True");
     
            public SqlConnection getcon()
            {
                if (con.State==ConnectionState.Closed)
                 {
                    con.Open();
                 }
                return con;
            }
            public int ExeNonQuery(SqlCommand cmd)
            {
                cmd.Connection=getcon();
                int rowsaffected = -1;
                rowsaffected=cmd.ExecuteNonQuery();
                con.Close();
                return rowsaffected;
            }
     
            public object ExeScalar(SqlCommand cmd)
            {
                cmd.Connection = getcon();
                object obj =-1;
                obj=cmd.ExecuteScalar();
                con.Close();
                return obj;
            }
            public DataTable ExeReader(SqlCommand cmd)
            {
                cmd.Connection = getcon();
                SqlDataReader sdr;
                DataTable dt = new DataTable();
     
                sdr= cmd.ExecuteReader();
                dt.Load(sdr);
                con.Close();
                return dt;
            }
        }
    }

  4. #4
    Membre confirmé Avatar de WaterTwelve21
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2015
    Messages
    270
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Décembre 2015
    Messages : 270
    Points : 461
    Points
    461
    Par défaut
    Bonjour ,

    Ceci n'est pas la commande mais le code de ta classe Dbconnection . Ce que te demande Prisson , c'est la valeur de ton paramètre cmd qui contient ta requête sql .

    Ton message d'erreur sur ton image est explicite et les pistes pour résoudre le problème se trouvent dans ce paramètre .
    throw new NoSignatureException();

  5. #5
    Membre régulier
    Inscrit en
    Janvier 2007
    Messages
    219
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 219
    Points : 76
    Points
    76
    Par défaut
    bonjour
    voici la commande

    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using DAL;
    using BEL;
    using System.Data;
    using System.Data.SqlClient;
     
    namespace BAL
    {
        public class Operations
        {
            public Dbconnection db = new Dbconnection();
            public Informations info = new Informations();
            // ici nous declarons les requete et db operation dont on a besoin pour l'application
     
     
            public int insertUsers (Informations info)
            {
                //throw new NotImplementedException();
                SqlCommand cmd =new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into users  VALUES ('" + info.nom + "','" + info.prenom + "','" + info.login + "','" + info.mdp + "','" + info.profil + "','" + info.datecreat + "','" + info.sexe + "')";
                return db.ExeNonQuery(cmd);
            }
     
            public DataTable login(Informations info)
            {
                //throw new NotImplementedException();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from users where login_users='"+info.login+"' and mdp_users='"+info.mdp+"'";
                return db.ExeReader(cmd);
            }
     
            public int insertprofil(Informations info)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into profil(libprofil) VALUES ('" + info.libprofil + "')";
                return db.ExeNonQuery(cmd);
            }
            public int insertmod(Informations info)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into mod(nommod,nomcompletmod,contactmod) VALUES ('" + info.nommod + "','" + info.nomcompletmod + "','" + info.contactmod + "')";
                return db.ExeNonQuery(cmd);
            }
            public int insertclient(Informations info)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into client(nomclient,nomcomplet,contact) VALUES ('" + info.nomclient + "','" + info.nomcomplet + "','" + info.contact+ "')";
                return db.ExeNonQuery(cmd);
            }
            public int insertbanque(Informations info)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into banque(codebanque,libanque,comptebanque,creepar) VALUES ('" + info.codebanque + "','" + info.libanque + "','" + info.comptebanque + "','" + info.creepar + "')";
                return db.ExeNonQuery(cmd);
            }
            public int insertprojet(Informations info)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into projet (titre_projet,lieu_projet,pays_projet,client_projet,mod_projet,perso_projet,nbperso_projet,adresse_projet,mont_projet,finance_projet,nbhomme_projet,datdemar_projet1,datdemar_projet2,datachev1_projet1,datachev2_projet1,datachev1_projet2,datachev2_projet2,mtetude_projet,mtsuivi_projet,mtetmdec_projet,consasso_projet,nbhcons_projet,respons_projet,descrip_projet,desserv_projet,creepar) VALUES ('" + info.titre_projet + "','" + info.lieu_projet + "','" + info.pays_projet + "','" + info.client_projet + "','" + info.mod_projet + "','" + info.perso_projet + "','" + info.nbperso_projet + "','" + info.adresse_projet + "','" + info.mont_projet + "','" + info.finance_projet + "','" + info.nbhomme_projet + "','" + Convert.ToDateTime(info.datdemar_projet1) + "','" + Convert.ToDateTime(info.datdemar_projet2) + "','" + Convert.ToDateTime(info.datachev1_projet1) + "','" + Convert.ToDateTime(info.datachev2_projet1) + "','" + Convert.ToDateTime(info.datachev1_projet2) + "','" + Convert.ToDateTime(info.datachev2_projet2) + "','" + info.mtetude_projet + "','" + info.mtsuivi_projet + "','" + info.mtetmdec_projet + "','" + info.consasso_projet + "','" + info.nbhcons_projet + "','" + info.respons_projet + "','" + info.descrip_projet + "','" + info.desserv_projet + "','" + info.creepar + "')";
                return db.ExeNonQuery(cmd);
            }
        }
    }

  6. #6
    Membre régulier
    Inscrit en
    Janvier 2007
    Messages
    219
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 219
    Points : 76
    Points
    76
    Par défaut
    les procedures d'insertion commence à marcher seulment des soucis avec tes champs de type text qui sont me pose des problèmes de gestion des exceptions

  7. #7
    Expert confirmé Avatar de ed73170
    Homme Profil pro
    Développeur indépendant
    Inscrit en
    Mai 2009
    Messages
    765
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur indépendant

    Informations forums :
    Inscription : Mai 2009
    Messages : 765
    Points : 5 522
    Points
    5 522
    Par défaut
    A ton avis, que se passe-t-il si une de tes valeurs contient une apostrophe ?

    Par exemple si info.nomcomplet est égal à "McDonald's".

    Mais peut-être l'as-tu prévu en amont dans la vérification de la validité des données de ta classe Informations.

  8. #8
    Membre régulier
    Inscrit en
    Janvier 2007
    Messages
    219
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 219
    Points : 76
    Points
    76
    Par défaut
    j'ai pas prévu cela, car c'est du texte qu'on saisie dans certain champ de la table, j'avais un compris mais je ne sais pas comment corrigé cela.
    les champs de type varchar(max)et texte peuvent contenir.
    comment corriger cela

  9. #9
    Membre actif
    Homme Profil pro
    Autodidacte
    Inscrit en
    Mars 2016
    Messages
    154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Brazzaville

    Informations professionnelles :
    Activité : Autodidacte
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2016
    Messages : 154
    Points : 268
    Points
    268
    Par défaut
    Bonjour,
    tu peux utiliser l'instruction Trim() pour reduire les espaces après saisi du texte et par la suite verifier la taille du texye saisi avec l'instruction Lengh avant validation de la saisie de l'utilisateur.
    Lengh te permet de ciomparer la saisie de l'utilisateur à la taille du string attendu dans la bd

  10. #10
    Membre régulier
    Inscrit en
    Janvier 2007
    Messages
    219
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 219
    Points : 76
    Points
    76
    Par défaut
    merci pour les informations, d'avance, je connais pas la taille des textes à saisir cela varie, c'est pour quoi j'ai defini le type varchar(max) et texte pour saisir la description des projets et des services demande; souvent certaines peuvent etre courte comme certaines peuvent être longues.

  11. #11
    Membre régulier
    Inscrit en
    Janvier 2007
    Messages
    219
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 219
    Points : 76
    Points
    76
    Par défaut
    merci tous, c'est résolu,

  12. #12
    Membre régulier
    Inscrit en
    Janvier 2007
    Messages
    219
    Détails du profil
    Informations forums :
    Inscription : Janvier 2007
    Messages : 219
    Points : 76
    Points
    76
    Par défaut resolu
    merci le problème est resolu

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

Discussions similaires

  1. [Débutant] utiliser plusieurs tables dans un application 3 tiers sous c#
    Par kitcarson23 dans le forum Visual Studio
    Réponses: 0
    Dernier message: 21/01/2017, 19h12
  2. Réponses: 3
    Dernier message: 29/05/2007, 20h37
  3. Utiliser un timer dans une application console
    Par chavers dans le forum Langage
    Réponses: 8
    Dernier message: 25/05/2005, 14h07
  4. [Applet]Utiliser plusieurs Applet dans une même classe
    Par BRAUKRIS dans le forum Applets
    Réponses: 5
    Dernier message: 11/06/2004, 15h27
  5. Réponses: 8
    Dernier message: 17/03/2004, 14h40

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