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

ADO.NET Discussion :

insertion d'une image dans sql server


Sujet :

ADO.NET

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2009
    Messages
    125
    Détails du profil
    Informations personnelles :
    Localisation : Tunisie

    Informations forums :
    Inscription : Décembre 2009
    Messages : 125
    Points : 90
    Points
    90
    Par défaut insertion d'une image dans sql server
    bonjour ,
    je cherche à insérer des images dans une base de données sql server mais je ne sais pas comment procéder.
    pour plus d'explication, j'ai une table ayant un champ "picture" avec un type image et je veux récupérer ces images et les afficher à un utilisateur.
    Comment introduire ce images dans la base en premier lieu et comment les récupérer aprés de la base et les afficher via une interface wpf ou desktop ou WP7?

    j'utilise visual studio 2010 et Sql Server 2008 et mon langage de programmation est C#.

    Merci de m'aider.

  2. #2
    Membre du Club
    Inscrit en
    Juillet 2010
    Messages
    41
    Détails du profil
    Informations forums :
    Inscription : Juillet 2010
    Messages : 41
    Points : 59
    Points
    59
    Par défaut
    Bonjour.

    Pour insérer ton image, convertit la en tableau de byte.
    C'est ce tableau que tu vas insérer dans ta table.
    Pour lire l'image tu fais l'inverse, tu récupère la valeur dans ta table sous forme de tableau de byte et tu le reconvertit en fichier.

    Tu as un exemple dans ce lien :
    http://www.daniweb.com/software-deve...rp/code/217419

    En espérant que cela peut t'aider.

    Cordialement.

  3. #3
    Membre chevronné Avatar de Er3van
    Homme Profil pro
    Architecte Logiciel
    Inscrit en
    Avril 2008
    Messages
    1 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Architecte Logiciel
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2008
    Messages : 1 430
    Points : 2 227
    Points
    2 227
    Par défaut
    Tu n'as même pas besoin, tu peux déclarer des formats "images" dans SQL Server 2008.
    One minute was enough, Tyler said, a person had to work hard for it, but a minute of perfection was worth the effort. A moment was the most you could ever expect from perfection.

    -- Chuck Palahniuk, Fight Club, Chapter 3 --

  4. #4
    Membre expert Avatar de iberserk
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Novembre 2004
    Messages
    1 795
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2004
    Messages : 1 795
    Points : 3 173
    Points
    3 173
    Par défaut
    Tu n'as même pas besoin, tu peux déclarer des formats "images" dans SQL Server 2008.
    Celà n'empèche pas qu'une conversion soit nécessaire côté C#

    Le type Image est déprécié depuis SQL SERVER 2005 il ne faut plus l'utiliser.
    Il est remplacé par le type VARBINARY(MAX).


    Depuis 2008 vous avez le nouveau type FILESTREAM très intéressant...
    Prendre conscience, c'est transformer le voile qui recouvre la lumière en miroir.
    MCTS Database Development
    MCTS Database Administration

  5. #5
    Rédacteur
    Avatar de WOLO Laurent
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Mars 2003
    Messages
    2 741
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Congo-Brazzaville

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2003
    Messages : 2 741
    Points : 4 414
    Points
    4 414
    Par défaut
    Voici un exemple pratique :

    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
    int IDAL_Paie.EMPLOYE_Insert(EMPLOYE dr)
            {
                using (DbConnection connection = db.CreateConnection())
                {
                    using (DbCommand command = db.GetStoredProcCommand("Employe_insert"))
                    {
                        db.AddInParameter(command, "PAY_NAISS", DbType.String, dr.PAY_NAISS);
                        db.AddInParameter(command, "SER_NOM", DbType.String, dr.SER_NOM);
                        db.AddInParameter(command, "TPC_LIB", DbType.String, dr.TPC_LIB);
                        db.AddInParameter(command, "SEX_LIB", DbType.String, dr.SEX_LIB);
                        db.AddInParameter(command, "DEP_DESIGN", DbType.String, dr.DEP_DESIGN);
                        db.AddInParameter(command, "PAY_NATION", DbType.String, dr.PAY_NATION);
                        db.AddInParameter(command, "SFA_LIB", DbType.String, dr.SFA_LIB);
                        db.AddInParameter(command, "FCT_NOM", DbType.String, dr.FCT_NOM);
                        db.AddInParameter(command, "CAT_ID", DbType.String, dr.CAT_ID);
                        db.AddInParameter(command, "ECH_ID", DbType.String, dr.ECH_ID);
                        db.AddInParameter(command, "PAY_RESID", DbType.String, dr.PAY_RESID);
                        db.AddInParameter(command, "COL_LIB", DbType.String, dr.COL_LIB);
                        db.AddInParameter(command, "MDP_LIB", DbType.String, dr.MDP_LIB);
                        db.AddInParameter(command, "TIT_LIB", DbType.String, dr.TIT_LIB);
                        db.AddInParameter(command, "PPY_NOM", DbType.String, dr.PPY_NOM);
                        db.AddInParameter(command, "EMP_MAT", DbType.String, dr.EMP_MAT);
                        db.AddInParameter(command, "EMP_NOM", DbType.String, dr.EMP_NOM);
                        db.AddInParameter(command, "EMP_PRENOM", DbType.String, dr.EMP_PRENOM);
                        db.AddInParameter(command, "EMP_NOM_J_FILLE", DbType.String, dr.EMP_NOM_J_FILLE);
                        db.AddInParameter(command, "EMP_NE_A", DbType.String, dr.EMP_NE_A);
                        db.AddInParameter(command, "EMP_NE_LE", DbType.DateTime, dr.EMP_NE_LE);
                        db.AddInParameter(command, "EMP_NUM_SECUSOC", DbType.String, dr.EMP_NUM_SECUSOC);
                        db.AddInParameter(command, "EMP_NBRE_ENFANTS", DbType.Int32, dr.EMP_NBRE_ENFANTS);
                        db.AddInParameter(command, "EMP_ADRESSE1", DbType.String, dr.EMP_ADRESSE1);
                        db.AddInParameter(command, "EMP_ADRESSE2", DbType.String, dr.EMP_ADRESSE2);
                        db.AddInParameter(command, "EMP_ADRESSE3", DbType.String, dr.EMP_ADRESSE3);
                        db.AddInParameter(command, "EMP_QUALIF", DbType.String, dr.EMP_QUALIF);
                        db.AddInParameter(command, "EMP_DATE_EMBAUCHE", DbType.DateTime, dr.EMP_DATE_EMBAUCHE);
                        db.AddInParameter(command, "EMP_BANQUE", DbType.String, dr.EMP_BANQUE);
                        db.AddInParameter(command, "EMP_CODE_BANQUE", DbType.Int32, dr.EMP_CODE_BANQUE);
                        db.AddInParameter(command, "EMP_CODE_GUICHET", DbType.Int32, dr.EMP_CODE_GUICHET);
                        db.AddInParameter(command, "EMP_CLERIB", DbType.Int32, dr.EMP_CLERIB);
                        db.AddInParameter(command, "EMP_PHOTO", DbType.Binary, dr.EMP_PHOTO);
                        db.AddInParameter(command, "EMP_TEL1", DbType.String, dr.EMP_TEL1);
                        db.AddInParameter(command, "EMP_TEL2", DbType.String, dr.EMP_TEL2);
                        db.AddInParameter(command, "EMP_EMAIL", DbType.String, dr.EMP_EMAIL);
                        db.AddInParameter(command, "EMP_TITULAIRE_COMPTE", DbType.String, dr.EMP_TITULAIRE_COMPTE);
                        db.AddInParameter(command, "EMP_NUM_CPTE", DbType.Decimal, dr.EMP_NUM_CPTE);
                        db.AddOutParameter(command, "EMP_ID", DbType.Int32, 32);
                        try
                        {
                            db.ExecuteNonQuery(command);
                            return (int)db.GetParameterValue(command, "EMP_ID");
                        }
                        catch
                        {
                            return -1;
                        }
                        finally
                        {
                            if (connection.State == ConnectionState.Open)
                                connection.Close();
                        }
                    }
                }
            }
    et la classe Employe

    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
    179
    180
    181
    182
    183
    184
    185
    186
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.Serialization;
    using Microsoft.Practices.Unity;
     
    namespace Domain
    {
        [DataContract]
        public partial class EMPLOYE
        {
            /// <summary>
            /// Identifiant de l'employé
            /// </summary>
            [DataMember]
            [Dependency]
            public long EMP_ID { get; set; }
     
            [DataMember]
            [Dependency]
            public string PAY_NAISS { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_TITULAIRE_COMPTE { get; set; }
     
            [DataMember]
            [Dependency]
            public string SER_NOM { get; set; }
     
            [DataMember]
            [Dependency]
            public string TPC_LIB { get; set; }
     
            [DataMember]
            [Dependency]
            public string SEX_LIB { get; set; }
     
            [DataMember]
            [Dependency]
            public string DEP_DESIGN { get; set; }
     
            [DataMember]
            [Dependency]
            public string PAY_NATION { get; set; }
     
            [DataMember]
            [Dependency]
            public string SFA_LIB { get; set; }
     
            [DataMember]
            [Dependency]
            public string FCT_NOM { get; set; }
     
            [DataMember]
            [Dependency]
            public string CAT_ID { get; set; }
     
            [DataMember]
            [Dependency]
            public string ECH_ID { get; set; }
     
            [DataMember]
            [Dependency]
            public decimal CEC_SALBASE { get; set; }
     
            [DataMember]
            [Dependency]
            public decimal EMP_NUM_CPTE { get; set; }
     
            [DataMember]
            [Dependency]
            public string PAY_RESID { get; set; }
     
            [DataMember]
            [Dependency]
            public string COL_LIB { get; set; }
     
            [DataMember]
            [Dependency]
            public string MDP_LIB { get; set; }
     
            [DataMember]
            [Dependency]
            public string TIT_LIB { get; set; }
     
            [DataMember]
            [Dependency]
            public string PPY_NOM { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_MAT { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_NOM { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_PRENOM { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_NOM_J_FILLE { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_NE_A { get; set; }
     
            [DataMember]
            [Dependency]
            public DateTime EMP_NE_LE { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_NUM_SECUSOC { get; set; }
     
            [DataMember]
            [Dependency]
            public int EMP_NBRE_ENFANTS { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_ADRESSE1 { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_ADRESSE2 { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_ADRESSE3 { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_QUALIF { get; set; }
     
            [DataMember]
            [Dependency]
            public DateTime EMP_DATE_EMBAUCHE { get; set; }
     
            [DataMember]
            [Dependency]
            public int EMP_ANCIENETE { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_BANQUE { get; set; }
     
            [DataMember]
            [Dependency]
            public int EMP_CODE_BANQUE { get; set; }
     
            [DataMember]
            [Dependency]
            public int EMP_CODE_GUICHET { get; set; }
     
            [DataMember]
            [Dependency]
            public int EMP_CLERIB { get; set; }
     
            [DataMember]
            [Dependency]
            public byte[] EMP_PHOTO { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_TEL1 { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_TEL2 { get; set; }
     
            [DataMember]
            [Dependency]
            public string EMP_EMAIL { get; set; }
        }
     
     
        public partial class EMPLOYE
        {
            public List<Domain.EST_CONSTITUE> ElementsConfigures { get; set; }
        }
    }
    vous pouvez enlever les décorateur [DataContrat], Dependency et Datamember.

    Découvrez la FAQ de MS SQL Server.
    La chance accorde ses faveurs aux esprits avertis !

  6. #6
    Rédacteur
    Avatar de WOLO Laurent
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Mars 2003
    Messages
    2 741
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Congo-Brazzaville

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2003
    Messages : 2 741
    Points : 4 414
    Points
    4 414
    Par défaut
    Nous n'avons pas eu de suite de ta part. Pouvons nous marquer ce post comme résolu ?

    Découvrez la FAQ de MS SQL Server.
    La chance accorde ses faveurs aux esprits avertis !

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

Discussions similaires

  1. inserer une image dans sql server
    Par marwa21 dans le forum MS SQL Server
    Réponses: 7
    Dernier message: 15/03/2011, 15h35
  2. [PHP 5.0] Probleme d'affichage d'une image dans SQL SERVER
    Par stentorus dans le forum Langage
    Réponses: 2
    Dernier message: 23/08/2010, 17h20
  3. syntaxe d'insertion d'une variable dans SQL Server
    Par hariri dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 20/04/2007, 17h00

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