簡體   English   中英

無法從數據庫中檢索圖像

[英]unable to retrieve image from database

c#代碼中沒有出現錯誤,但創建的Web設計不顯示圖像。 *使用SQL Server管理工作室將圖像路徑存儲在數據庫的列中。 *將數據庫連接到我的項目,其中有一個包含圖像控件的網格視圖。 *存儲圖像的文件夾位於項目文件夾中。

*我已經嘗試更改不同的路徑,為圖像控件添加一些高度和重量屬性。

徽標是數據庫中列的名稱,其中給出了圖像的路徑。 在此輸入圖像描述

從圖像中檢索除數據庫之外的所有內容 在此輸入圖像描述

我希望在運行.aspx頁面后顯示圖像。

  ----AdminPage.aspx-------------
     <ItemTemplate>
     <asp:Image ID="Image1" ImageUrl="" runat="server" Width="50" Height="50"/>
      </ItemTemplate>


      ----AdminPage.aspx.cs-------------

       protected void Page_Load(object sender, EventArgs e)
    {
        string str = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
       SqlConnection con = new SqlConnection(str);
       con.Open();
        SqlCommand cmd = new SqlCommand("select Logo from TableName", con);
        cmd.CommandType = CommandType.Text;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        if (ds.Tables[0].Rows.Count > 0)
        {
            Image1.ImageUrl = "../PIC/" + ds.Tables[0].Rows[0]["Logo"].ToString();

        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM