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

Windows Forms Discussion :

PictureBox + Erreur System.DBNull en type System.Byte + If [Débutant]


Sujet :

Windows Forms

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    323
    Détails du profil
    Informations personnelles :
    Localisation : Espagne

    Informations forums :
    Inscription : Juillet 2003
    Messages : 323
    Points : 112
    Points
    112
    Par défaut PictureBox + Erreur System.DBNull en type System.Byte + If
    Salut !

    J'ai un Datagrid qui m'affiche ce qu'il y a dans ma BD.
    Mais le hic c'est que il n'y a pas d'image et et la valeur de BLOB est NULL,
    je me tape ce jolie message d'erreur quand je clique sur mon DataGrid

    'System.DBNull' en type 'System.Byte[]'.

    Comment puis je faire un If pour cette commande.
    Je laisse mon code sa m'aidera pour les prochains

    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
            If e.RowIndex >= 0 Then
                Dim row As DataGridViewRow
                row = Me.DataGridView1.Rows(e.RowIndex)
                TextBox2.Text = row.Cells("nombre").Value.ToString
                TextBox3.Text = row.Cells("apellidos").Value.ToString
                TextBox4.Text = row.Cells("dni").Value.ToString
                TextBox5.Text = row.Cells("calle").Value.ToString
                TextBox6.Text = row.Cells("poblacion").Value.ToString
                TextBox7.Text = row.Cells("cp").Value.ToString
                TextBox8.Text = row.Cells("provincia").Value.ToString
                TextBox9.Text = row.Cells("nacionalidad").Value.ToString
                DateTimePicker1.Text = row.Cells("fecha_nacimiento").Value.ToString
                TextBox10.Text = row.Cells("lugar_nacimiento").Value.ToString
                DateTimePicker2.Text = row.Cells("fecha_entrada").Value.ToString
                DateTimePicker3.Text = row.Cells("fecha_baja").Value.ToString
                DateTimePicker4.Text = row.Cells("fecha_baja_definitiva").Value.ToString
                ComboBox1.Text = row.Cells("empresa").Value.ToString
                ComboBox2.Text = row.Cells("lugar_trabajo").Value.ToString
                ComboBox3.Text = row.Cells("puesto").Value
     
                Dim data As Byte() = row.Cells("foto").Value
                Dim ms As New MemoryStream(Data)
                PictureBox1.Image = Image.FromStream(MS)
            End If
    Merci d'avance.....

  2. #2
    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 ,

    Je vais peut être un peu vite en besogne , mais un simple test de nullité ne ferai t-il pas l'affaire ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(Image.FromString(MS) != null ) //Ou DBNull.Value
    throw new NoSignatureException();

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    323
    Détails du profil
    Informations personnelles :
    Localisation : Espagne

    Informations forums :
    Inscription : Juillet 2003
    Messages : 323
    Points : 112
    Points
    112
    Par défaut
    Merci WaterTwelve21 d'avoir repondu,

    Mais entre temps j'ai trouver une solucion qui me satisfait.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
                If IsDBNull(row.Cells("foto").Value) = True Then
                    PictureBox1.Image = Nothing
                Else
                    Dim data As Byte() = row.Cells("foto").Value
                    Using ms As New MemoryStream(data)
                        PictureBox1.Image = Image.FromStream(ms)
                    End Using
                End If

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

Discussions similaires

  1. Réponses: 4
    Dernier message: 04/07/2016, 22h56
  2. Réponses: 9
    Dernier message: 22/04/2016, 17h30
  3. Réponses: 12
    Dernier message: 18/03/2014, 10h42
  4. Réponses: 9
    Dernier message: 01/10/2013, 11h32
  5. Réponses: 2
    Dernier message: 06/03/2007, 19h38

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