如何在asp.net中从数据库检索图像到gridview?

时间:2018-02-06 09:39:56

标签: c# asp.net sql-server-2005

我只想存储和检索从数据库到gridview的图像。存储图像后,我想在网格视图中显示存储的图像。怎么办?

  

在asp.net中将图像从数据库检索到gridview

protected void Page_Load(object sender, EventArgs e)
        {

            if (!this.IsPostBack)
            {
                BindGridView();
            }

        }
        private void BindGridView()
        {
            string constr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
            SqlConnection con = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand("select * from Student", con);
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);

            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

0 个答案:

没有答案