从数据库中获取imagepath并在c#中的图像控件中显示

时间:2017-05-12 07:23:19

标签: c# sql asp.net

我正在尝试从数据库中获取图像的图像路径并将其显示在图像控件中,但图像未显示。我试过了:

public void FetchQimage()
{
    connection.Open();

    SqlCommand cmd = new SqlCommand("select image_path from Questionimage where sub_code = '" + Session["subject"] + "' ", connection);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);

    if (dt.Rows.Count > 0)
    {
        // for (int i = 0; i <= dt.Rows.Count - 1; i++)
        // {

        Image3.ImageUrl = dt.Rows[0]["image_path"].ToString();
    }
}

图像路径的格式为:D:\ Project \ projectxyz \ image

0 个答案:

没有答案
相关问题