问题如下:
    我希望能在table的指定的td里显示出我从sql server里
    取到的image类型数据,不知道有没有办法做到?
    
    我所知道的一般在页面上显示sql server image类型数据
    的方法如下:
    1.从sql server中取到的image类型的数据,将其存储到
    byte[]数组里面
    2.设置Response.ContentType="image/gif"
    3.用Response.BinaryWrite方法显示出来
    
    
    但我不知道该如何指定位置。
    请高人指点一下,非常感谢!

解决方案 »

  1.   

    有时候我们需要保存一些binary data进数据库。SQL Server提供一个叫做image的特殊数据类型供我们保存binary data。Binary data可以是图片、文档等。在这篇文章中我们将看到如何在SQL Server中保存和输出图片。  建表   为了试验这个例子你需要一个含有数据的table(你可以在现在的库中创建它,也可以创建一个新的数据库),下面是它的结构: 
    Column Name 
    Datatype 
    Purpose 
    ID 
    Integer 
    identity column Primary key IMGTITLE 
    Varchar(50) 
    Stores some user friendly title to identity the image IMGTYPE 
    Varchar(50) 
    Stores image content type. This will be same as recognized content types of ASP.NET IMGDATA 
    Image 
    Stores actual image or binary data.
    保存images进SQL Server数据库  为了保存图片到table你首先得从客户端上传它们到你的web服务器。你可以创建一个web form,用TextBox得到图片的标题,用HTML File Server Control得到图片文件。确信你设定了Form的encType属性为multipart/form-data。 
    Stream imgdatastream = File1.PostedFile.InputStream; 
    int imgdatalen = File1.PostedFile.ContentLength; string imgtype = File1.PostedFile.ContentType; string imgtitle = TextBox1.Text; byte[] imgdata = new byte[imgdatalen]; int n = imgdatastream.Read(imgdata,0,imgdatalen); string connstr= ((NameValueCollection)Context.GetConfig ("appSettings"))["connstr"]; SqlConnection connection = new SqlConnection(connstr); SqlCommand command = new SqlCommand ("INSERT INTO ImageStore(imgtitle,imgtype,imgdata) VALUES ( @imgtitle, @imgtype,@imgdata )", connection ); 
    SqlParameter paramTitle = new SqlParameter ("@imgtitle", SqlDbType.VarChar,50 ); paramTitle.Value = imgtitle; command.Parameters.Add( paramTitle); 
    SqlParameter paramData = new SqlParameter ( "@imgdata", SqlDbType.Image ); paramData.Value = imgdata; command.Parameters.Add( paramData ); 
    SqlParameter paramType = new SqlParameter ( "@imgtype", SqlDbType.VarChar,50 ); paramType.Value = imgtype; command.Parameters.Add( paramType ); 
    connection.Open(); int numRowsAffected = command.ExecuteNonQuery(); connection.Close(); 
       
       
      

  2.   


    http://dotnet.aspx.cc/ShowDetail.aspx?id=2A5DD7C6-A45A-48AB-A2E8-342A29F17506
    http://dotnet.aspx.cc/ShowDetail.aspx?id=ECD9AE16-8FF0-4A1C-9B9F-5E8B641CB1B1
      

  3.   

    答非所问!把图片流写到页面上
    显示的位置没发用<td>来定位,好像不管用.
    试试:在<td>里放一个iframe来控制.把显示图片的页面放iframe里
      

  4.   

    <td><img src=show.aspx?ID=888></td>
    show.aspx的page_load中写读图片流的代码
      

  5.   

    TO:noahart(八卦小子)呵呵,什么答非所问啊例子给的就是image控件,结合页面来做的,标准的定位,怎么会答非所问
      

  6.   

    http://ulinkdir.tom.com/tomulink/2004/05/17/ent_20040517175836.html?d=www.pcsky.cn&u=http%3A//www.pcsky.cn/ads/ad_txt_tom300.htm&t=1084794443500
    看看这个是怎样用C#+Sql Server存取图像的
      

  7.   

    谢谢大家的参已,问题已经解决,特别感谢tavor(龙双公子) 提供的资料。
    我过一段时间在结帖,让有需要的朋友也能看看。