- 爱易网页
-
ASP.NET教程
- 从数据库读取二进制图片写出来是个叉叉`搞了良久了`
日期:2014-05-19 浏览次数:20611 次
从数据库读取二进制图片写出来是个叉叉````急``搞了好久了```
我的代码如下```
private void WriteFrom(string id)
{
OleDbConnection conn =new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Documents and Settings\\icyleaf\\My Documents\\Visual Studio 2005\\WebSites\\WebShop\\App_Data\\WebShopDateSource.mdb ");
OleDbCommand cmd = new OleDbCommand( "SELECT Picture FROM dbo_Categories WHERE CategoryID= "+id,conn);
try
{
conn.Open();
Byte[] bt = (Byte[])cmd.ExecuteScalar();
Response.ClearContent();
Response.ContentType = "image/Gif ";
Response.BinaryWrite(bt);
}
catch (Exception e)
{
Response.Write( " <h1> wrong!!!!!! </h1> "+e);
}
finally {
Response.End();
conn.Close();
}
}
这段代码可以说基本是在网上抄的咯``但我读出来之后还是个叉叉```
aspx文件里的代码是这样的
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "WriteImages.aspx.cs " Inherits= "WriteImages " %>
只有这一句```
急求各位大侠帮忙下了```搞了好久了``不知道为什么```
------解决方案--------------------
参考显示图片页的代码:
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString[ "id "];
if (id != null && id.CompareTo( " ") != 0)
{
string connStr = ConfigurationManager.ConnectionStrings[ "ConnString "].ConnectionString;
string SqlStr = "SELECT * FROM test02 where id = " + id;
DataSet ds = new DataSet();
try
{
SqlConnection conn = new SqlConnection(connStr);