如何在WPF中使用c#显示mysql数据库中的图像?

时间:2013-07-26 10:36:20

标签: c# mysql wpf

 string constring = "server=localhost;uid=root;" + "pwd=12345;database=products;";
            string query = "SELECT prd_items_image FROM products.prd_items where prd_items_id=5";
            MySqlConnection condatabase = new MySqlConnection(constring);
            MySqlCommand cmddatabase = new MySqlCommand(query, condatabase);
            MySqlDataReader myreader;
            try
            {
                condatabase.Open();
                myreader = cmddatabase.ExecuteReader();
                while (myreader.Read())
                {
                    byte[] imgg = (byte[])(myreader["prd_items_image"]);
                    if (imgg == null)
                        box.Image = null;
                    else
                    {
                        MemoryStream mstream = new MemoryStream(imgg);
                       box.Image = System.Drawing.Image.FromStream(mstream);
                    }
                }

我遇到条件错误,

box.Image=null andbox.Image = System.Drawing.Image.FromStream(mstream);

在这两种情况下,我在Image处收到错误。 所以请检查一次。如果您有任何其他代码,请在需要时提供。

0 个答案:

没有答案