Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ASP.NET从SQL Server显示图像_Asp.net_Sql Server - Fatal编程技术网

使用ASP.NET从SQL Server显示图像

使用ASP.NET从SQL Server显示图像,asp.net,sql-server,Asp.net,Sql Server,查看注释和代码后,可以使用以下代码 protected void ddlitemname_TextChanged (object sender, EventArgs e) { DataSet ds = Common.ExecuteQuery("select * from Tbl_Item_Master where Category='" + ddlitemname.SelectedItem.Text + "'"); if (ds.Tables[0].Rows.Count >

查看注释和代码后,可以使用以下代码

protected void ddlitemname_TextChanged (object sender, EventArgs e)
{
    DataSet ds = Common.ExecuteQuery("select * from Tbl_Item_Master where Category='" + ddlitemname.SelectedItem.Text + "'");

    if (ds.Tables[0].Rows.Count > 0)
    {
        txthscode.Text = ds.Tables[0].Rows[0]["Hscode"].ToString();
        txtselect.Text = ds.Tables[0].Rows[0]["specification"].ToString();
        txttax.Text = ds.Tables[0].Rows[0]["Tax"].ToString();
        lblphoto.Text = ds.Tables[0].Rows[0]["Photo"].ToString();
    }
}

受保护的无效ddlitemname\u text已更改(对象发送方,事件参数e)
{
数据集ds=Common.ExecuteQuery(“从Tbl_Item_Master中选择*,其中Category='”+ddlitemname.SelectedItem.Text+'”


}

通过查看代码,您似乎在使用标签(lblphoto)而不是图像控件。它应该是图像控件img.src=ds.Table[0]。行[0][“photo”].ToString()我尝试使用img1.ImageUrl=ds.Tables[0]。行[0][“photo”].ToString();但不起作用。您在数据库中存储的图像是URL还是BLOB二进制数据?如果已存储Blob字段,则编写一个处理程序以显示image.string filename=“”;如果(fupphoto.HasFile){filename=Path.GetFileName(fupphoto.PostedFile.filename);fupphoto.PostedFile.SaveAs(Server.MapPath(“Image/”+filename));}url绑定网格后检查映像的路径。由于您正在使用图像文件夹,而数据库中的图像文件夹似乎是u保存的唯一文件名。找不到资源。
 <asp:Image ID="img1" runat="server" ImageUrl =<%# string.Format("~/image/{0}",Eval("Photo"))%>
if (ds.Tables[0].Rows.Count > 0)
{
    txthscode.Text = ds.Tables[0].Rows[0]["Hscode"].ToString();
    txtselect.Text = ds.Tables[0].Rows[0]["specification"].ToString();
    txttax.Text = ds.Tables[0].Rows[0]["Tax"].ToString();
    img1.ImageUrl = "~/Image/" + ds.Tables[0].Rows[0]["Photo"].ToString();
}