【发布时间】:2013-08-02 13:12:03
【问题描述】:
我在 SQL Server 2008 中有一个表 images,它包含两列 imageid 和 image。我可以使用FileUpload 控制器和图像将图像插入image 列,并将图像转换为二进制形式进行存储。现在我想在与图像 id 对应的图像框中显示图像。我正在使用一个文本框让用户输入id,并使用一个按钮来执行显示命令。
public void ShowImage()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["anu"].ToString();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Select ID,Image from Images where ID=" + txtid.Text;
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
con.Open();
SqlDataReader dreader = cmd.ExecuteReader();
dreader.Read();
Context.Response.BinaryWrite((byte[])dreader["image"]);
dreader.Close();
con.Close();
}
此代码运行良好,但它会将图像加载到单独的页面中,但我需要将其显示在特定的图像框中。我的前端是 ASP.NET。如果哪位知道答案,请帮帮我。
【问题讨论】:
-
这不是 SQL,因为 SQL 正在运行。您的问题是 asp.net,因此请根据需要更改标签
标签: asp.net sql image sql-server-2008