none
从数据库查找图片的问题. RRS feed

  • 问题

  • 我有一个asp.net 程序, 我把图片存储在数据库中,我查询的时候出现问题了。报这样的错误:

    Error 1 'System.Web.UI.WebControls.Image' does not contain a definition for 'Image' and no extension method 'Image' accepting a first argument of type 'System.Web.UI.WebControls.Image' could be found (are you missing a using directive or an assembly reference?) 
    
    Error 2 'Image' is an ambiguous reference between 'System.Drawing.Image' and 'System.Web.UI.WebControls.Image' 
    

    这个是我的代码:

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Drawing;
    using System.Web.UI.WebControls;
    private void LoadImage()
        {
           SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0; AttachDbFilename=C:\Users\Donald\Documents\Visual Studio 2013\Projects\DesktopApplication\DesktopApplication\Student_CB.mdf ;Integrated Security=True");
            con.Open();
            try
            {
                //Fetching top recipe     
                string query = "Select Image FROM Recipe_Image where Image_Name = '"+VeganLbl1.Text+"'";
                SqlCommand command = new SqlCommand(query, con);
                SqlDataAdapter da = new SqlDataAdapter(command);
                DataTable dt = new DataTable();
               da.Fill(dt);
                byte[] img = (byte[])dt.Rows[0][0];
                MemoryStream ms = new MemoryStream(img);
                Image1.Image = Image.FromStream(ms);
               da.Dispose();
           }
            catch (Exception)
            {
            }
             con.Close();
        }
    

     有人帮我看一下,错误出现在那里吗?

    2016年4月10日 7:39

答案

全部回复