从数据库中检索名称和图像,其中图像存储为上载文件夹,引用存储在数据库中?

时间:2019-03-19 11:25:23

标签: asp.net

尝试以下代码,但无法获得所需的结果。
我已将图像存储在上载文件夹中,并且其引用已保存在数据库中,同时从管理端将数据存储在数据库中。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;


namespace Admin
{
public partial class fetch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string cs = 
  ConfigurationManager.ConnectionStrings["DBSC"].ConnectionString;
        using (SqlConnection con = new SqlConnection(cs))
        {
            SqlCommand cmd = new SqlCommand("spUploadImage", con);
            cmd.CommandType = CommandType.StoredProcedure;


            SqlParameter ParamId = new SqlParameter()
            {
                ParameterName = "@Id",

                Value = Request.QueryString["Id"]


            };

            cmd.Parameters.Add(ParamId);
            con.Open();
            byte[] Bytes = (byte[])cmd.ExecuteScalar();

            string strBase64 = Convert.ToBase64String(bytes);

            FileUpload1.ImageUrl = "data:image/png;base64, +strBase64";


        }
    }
  }
}

0 个答案:

没有答案