Bonjours, bonsoirs,
Depuis quelque jour, j'essaye d'améliorer mon logiciel.
J'essaye de réorganiser mes tables etc... de MySQL, mais d'un côté, dans mon logiciel chaque utilisateur pourra mettre une image de profil.
J'arrive a le faire, si je met le lien dans la table SQL, mais, je trouve pas très pratique que l'utilisateur va dans un site d'hébergement d'image qui ensuite donne le lien.
Alors j'essaie de mettre l'image dans la bdd, voici ce que j'ai fait:
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
byte[] blob;
        private void ConnectDataSQL()
        {
            using (MD5 md5Hash = MD5.Create())
            {
                hash = GetMd5Hash(md5Hash, this.user_mdp);
 
                Console.WriteLine("The MD5 hash of " + this.user_mdp + " is: " + hash + ".");
 
                Console.WriteLine("Verifying the hash...");
 
                if (VerifyMd5Hash(md5Hash, this.user_mdp, hash))
                {
                    Console.WriteLine("The hashes are the same.");
                }
                else
                {
                    Console.WriteLine("The hashes are not same.");
                }
            }
            var userHost = Dns.GetHostName();
            var GetComputer_InternetIP = Dns.GetHostEntry(userHost).AddressList[1].ToString();
            rpgmshare.Connect c = new rpgmshare.Connect();
            MySqlConnection conn = new MySqlConnection("SERVER = " + c.serverName + "; PORT = " + c.serverHost + "; DATABASE = " + c.serverDbd + "; USERID = " + c.serverId + "; PASSWORD = " + c.serverMdp);
            conn.Open();
            MySqlCommand ip_user = new MySqlCommand("UPDATE User SET ip ='" + GetComputer_InternetIP.ToString() + "' WHERE username='" + this.user_pseudo + "'", conn);
            MySqlCommand verify_user = new MySqlCommand("SELECT userid, email, date, ip, image FROM User WHERE username='" + this.user_pseudo + "' and password = '" + hash + "'", conn);
            try
            {
                MySqlDataReader reader_verify_user = verify_user.ExecuteReader();
                if (reader_verify_user.HasRows)
                {
                    while (reader_verify_user.Read())
                    {
                        ID = reader_verify_user.GetInt32(0);
                        email = reader_verify_user.GetString(1);
                        date_inscrit = reader_verify_user.GetString(2);
                        IP = reader_verify_user.GetString(3);
                        image_profil = reader_verify_user.GetString(4);
                        blob = (byte[])reader_verify_user[4];
                    }
                    reader_verify_user.Close();
                    conn.Close();
                    conn.Open();
                    ip_user.ExecuteNonQuery();
                    conn.Close();
                    conn.Open();
                    MySqlCommand verify_user_connexion = new MySqlCommand("SELECT userid FROM Connexion WHERE userid = '" + ID + "'", conn);
                    MySqlDataReader reader_user_connexion = verify_user_connexion.ExecuteReader();
                    if (reader_user_connexion.HasRows)
                    {
                        reader_user_connexion.Close();
                        if (MessageBox.Show("Vous êtes déjà connecter!\nSe reconnecter?", "Server", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            MySqlCommand delete_connexion = new MySqlCommand("DELETE FROM Connexion WHERE userid = '" + ID + "'", conn);
                            try
                            {
                                delete_connexion.ExecuteNonQuery();
                                conn.Close();
                                ConnectDataSQL();
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }
                    else
                    {
                        reader_user_connexion.Close();
                        conn.Close();
                        conn.Open();
                        MySqlCommand insert_connexion = new MySqlCommand("INSERT INTO Connexion(IP, userid, last_connexion) VALUE('" + GetComputer_InternetIP.ToString() + "', '" + ID + "', '" + DateTime.Now.ToString() + "')", conn);
                        insert_connexion.ExecuteNonQuery();
                        conn.Close();
                        GetFriends();
                        //this.reussite = true;
                        //a.BeginInvoke((MethodInvoker)(() => a.Show()));
                    }
                }
                else
                {
                    MessageBox.Show("L'identifiant ou le mot de passe est incorrect!", "Connexion", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.reussite = false;
                }
                conn.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                throw;
            }
        }
Ensuite dans form accueil je récupére le byte et j'essaye de le convertir:
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
public Accueil(int ID, string Username, string Email, string Date_Inscrit, byte[] Image_Profil)
        {
            InitializeComponent();
            this.tabPage4.Text = Username;
            this.user_id = ID;
            this.username = Username;
            this.email = Email;
            this.metroTabControl1.SelectedIndex = 0;
            Games_DBB();
            CreateListGames();
            this.dateProfil.Text = "Inscrit le : \n" + Date_Inscrit;
            MemoryStream ms = new MemoryStream(Image_Profil);
            this.ImgProfil.Image = Image.FromStream(ms);
            this.ImgMiniProfil.Image = Image.FromStream(ms);
        }
 
        private Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            ms.Position = 0;
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }
Bref, j'ai essayer plusieurs manière, mais fonctionne pas soit l'erreur de Image.FromStream "Manque de paramètre".
Que des soucis, alors je vient vers vous si vous pouviez m'aidez.