读取sql server 数据库图片信息
以下来自,他的内容
摘要
.NET是由微软开发的一种新型的分布式计算平台,ASP.NET是它针对Web开发的编程模式。本文的目的是在开发数据驱动的ASP.NET Web应用程序中获取一些好的经验。这个应用程序将告诉你怎么把一幅图片保存到数据库中以及怎样把图片从数据库中读取出来。它以ADO.NET作为数据访问机制,C#作为编程语言,SQL 2000 Server作为后台数据库。
概述
一般的,很大的图片文件往往被保存在Web服务器的文件夹中,而不是数据库中。在一些实例中,以银行系统为例,人们先把用户的签名做成图片文件,然后保存到数据库中。
- 数据库模式
在这个示范中,微软的SQL 2000 Server被用作后台数据库。我使用了一种比较特殊的数据类型 image 。这 image 数据类型是被用来保存图片到数据库的。
- 所使用的控件: 
- System.Web.UI.HtmlControls.HtmlInputFile
- System.Web.UI.WebControls.TextBox
- System.Web.UI.WebControls.Button
 
using System.Data.SqlClient;
using System.Drawing;
using System.Data;
using System.IO;
using System.Drawing.Imaging;
编码
使用 HtmlInputFile 类,它可以用 <input type="file" runat="server"/> 标签来声明一个实例。下面的例子是一个完整的 ASPX 文件,它让用户上传图片文件以及图片的说明。OnUpload 方法把图片以及说明写到iSense 数据库的Picture 表中

 1// 保存图片文件到数据库的源码
1// 保存图片文件到数据库的源码
 2
 2  3public void OnUpload(Object sender, EventArgs e)
 3public void OnUpload(Object sender, EventArgs e) 4{
 4{ 5// 从输入文件中创建一个 byte[]
 5// 从输入文件中创建一个 byte[] 6int len = Upload.PostedFile.ContentLength;
 6int len = Upload.PostedFile.ContentLength; 7    byte[] pic = new byte[len];
 7    byte[] pic = new byte[len]; 8    Upload.PostedFile.InputStream.Read (pic, 0, len);
 8    Upload.PostedFile.InputStream.Read (pic, 0, len); 9// 插入图片和说明到数据库中
 9// 插入图片和说明到数据库中 10 SqlConnection connection = new
10 SqlConnection connection = new  11     SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=india");
11     SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=india"); 12    try
12    try 13    {
13    { 14        connection.Open ();
14        connection.Open (); 15        SqlCommand cmd = new SqlCommand ("insert into Image "
15        SqlCommand cmd = new SqlCommand ("insert into Image "  16          + "(Picture, Comment) values (@pic, @text)", connection);
16          + "(Picture, Comment) values (@pic, @text)", connection); 17        cmd.Parameters.Add ("@pic", pic);
17        cmd.Parameters.Add ("@pic", pic); 18        cmd.Parameters.Add ("@text", Comment.Text);
18        cmd.Parameters.Add ("@text", Comment.Text); 19        cmd.ExecuteNonQuery ();
19        cmd.ExecuteNonQuery (); 20    }
20    } 21    finally
21    finally  22    {
22    { 23        connection.Close ();
23        connection.Close (); 24    }
24    } 25}
25} 26
26 

上面创建的函数可以通过使用按钮的 onClick 属性来调用。
如何使用ADO.NET技术从数据库中读取图片并把它显示在Web页面上?
这里,我使用Web页面来显示图片,而没有用其他任何控件。下面的代码是用来显示数据库中的图片。
 private void Page_Load(object sender, System.EventArgs e)
private void Page_Load(object sender, System.EventArgs e)2
 {
{3
 MemoryStream stream = new MemoryStream ();
    MemoryStream stream = new MemoryStream ();4
 SqlConnection connection = new
    SqlConnection connection = new 5
 SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=india");
      SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=india");6
 try
    try7
 {
    {8
 connection.Open ();
        connection.Open ();9
 SqlCommand command = new
        SqlCommand command = new 10
 SqlCommand ("select Picture from Image", connection);
          SqlCommand ("select Picture from Image", connection);11
 byte[] image = (byte[]) command.ExecuteScalar ();
        byte[] image = (byte[]) command.ExecuteScalar ();   12
 stream.Write (image, 0, image.Length);
        stream.Write (image, 0, image.Length);13
 Bitmap bitmap = new Bitmap (stream);
        Bitmap bitmap = new Bitmap (stream);14
 Response.ContentType = "image/gif";
        Response.ContentType = "image/gif";15
 bitmap.Save (Response.OutputStream, ImageFormat.Gif);
        bitmap.Save (Response.OutputStream, ImageFormat.Gif);16
 }
    } 17
 finally
    finally18
 {
    {19
 connection.Close ();
        connection.Close ();20
 stream.Close ();
        stream.Close ();21
 }
    }22
 }
}23

GDI+函数为操作和定义图片提供了一个丰富的功能集合。本文的例子只能看到它的一小部分功能。你可以使用 System.Drawing 和 System.Drawing.Imaging 名字空间来调用这些功能。举例来说,你可以开发在Web上保存和管理图片文件的应用程序,或者你可以一个简单、易配置的应用程序使用户能够操作图片。
如何运行程序?
首先,创建一个虚拟目录,把你的工程文件放到这虚拟目录中。然后改变服务器名称,数据库名称以及表的名称,如下所示:
 SqlConnection connection = new SqlConnection("server=localhost;database=mypictures;uid=sa;pwd=");
SqlConnection connection = new SqlConnection("server=localhost;database=mypictures;uid=sa;pwd=");然后公布你的工程以获得最好的结果。
下面我我的体会:
使用背景: 在查询出来的 用户信息 ,双击用户,弹出包括相片的用户基本信息
在CombinationQueryShow.aspx  的datagrid_ItemDataBound 事件里面写如下
 if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) {
            { //为数据项添加鼠标单击属性 打开
                //为数据项添加鼠标单击属性 打开 e.Item.Attributes.Add("ondblclick", "window.open('Person_ContentShow.aspx?PersonInfoID="+e.Item.Cells[0].Text+"' ,'个人信息详细显示','width=800,height=600,resizable=yes,top=100,left=100'"+");");
                e.Item.Attributes.Add("ondblclick", "window.open('Person_ContentShow.aspx?PersonInfoID="+e.Item.Cells[0].Text+"' ,'个人信息详细显示','width=800,height=600,resizable=yes,top=100,left=100'"+");"); 
                         }
            }
Person_ContentShow.aspx 页面的HTML 内容如下:
 <%@ Page language="c#" Codebehind="Person_ContentShow.aspx.cs" AutoEventWireup="false" Inherits="Oceansoft.LGB.WEBUI.admin.search.Person_ContentShow" %>
<%@ Page language="c#" Codebehind="Person_ContentShow.aspx.cs" AutoEventWireup="false" Inherits="Oceansoft.LGB.WEBUI.admin.search.Person_ContentShow" %>2
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >3
 <HTML>
<HTML>4
 <HEAD>
    <HEAD>5
 <title>个人详细信息显示</title>
        <title>个人详细信息显示</title>6
 <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
        <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">7
 <meta content="C#" name="CODE_LANGUAGE">
        <meta content="C#" name="CODE_LANGUAGE">8
 <meta content="JavaScript" name="vs_defaultClientScript">
        <meta content="JavaScript" name="vs_defaultClientScript">9
 <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">10
 <LINK href="../images/left.css" type="text/css" rel="stylesheet">
        <LINK href="../images/left.css" type="text/css" rel="stylesheet">11
 </HEAD>
    </HEAD>12
 <body MS_POSITIONING="GridLayout">
    <body MS_POSITIONING="GridLayout">13
 <form id="Form1" method="post" runat="server">
        <form id="Form1" method="post" runat="server">14
 <table id="Maintable" height="100%" width="100%" border="2">
            <table id="Maintable" height="100%" width="100%" border="2">15
 <tr>
                <tr>16
 <td>
                    <td>17
 <asp:panel id="Panel1" style="OVERFLOW: auto" runat="server" Height="100%" Width="100%">
                        <asp:panel id="Panel1" style="OVERFLOW: auto" runat="server" Height="100%" Width="100%">18
 <TABLE id="table1" height="10%" width="100%" border="1">
                            <TABLE id="table1" height="10%" width="100%" border="1">19
 <TR>
                                <TR>20
 <TD width="45%" height="30">
                                    <TD width="45%" height="30">21
 <asp:label id="PersonID" Width="80" Runat="server" text="人员编号:"></asp:label>
                                        <asp:label id="PersonID" Width="80" Runat="server" text="人员编号:"></asp:label>22
 <asp:label id="lblPersonID" Runat="server" text=""></asp:label></TD>
                                        <asp:label id="lblPersonID" Runat="server" text=""></asp:label></TD>23
 <TD width="45%" height="30">
                                    <TD width="45%" height="30">24
 <asp:label id="enjoydeal" Width="80" Runat="server" text="现享受待遇:"></asp:label>
                                        <asp:label id="enjoydeal" Width="80" Runat="server" text="现享受待遇:"></asp:label>25
 <asp:label id="lblenjoydeal" Runat="server" text=""></asp:label></TD>
                                        <asp:label id="lblenjoydeal" Runat="server" text=""></asp:label></TD>26
 <TD align="center" rowSpan="3">照片
                                    <TD align="center" rowSpan="3">照片27
 <BR>
                                        <BR>28
 <FONT face="宋体"><IMG height=80
                                        <FONT face="宋体"><IMG height=80 29
 src='ImagePage.aspx?PersonInfoID=<%=Request.QueryString["PersonInfoID"]%>'
            src='ImagePage.aspx?PersonInfoID=<%=Request.QueryString["PersonInfoID"]%>' 30
 width=80> </FONT>
            width=80> </FONT>31
 </TD>
                                    </TD>32
 </TR>
                                </TR>33
 <TR>
                                <TR>34
 <TD width="45%" height="30">
                                    <TD width="45%" height="30">35
 <asp:label id="PersonName" Width="80" Runat="server" text="姓名:"></asp:label>
                                        <asp:label id="PersonName" Width="80" Runat="server" text="姓名:"></asp:label>36
 <asp:label id="lblPersonName" Runat="server" text=""></asp:label></TD>
                                        <asp:label id="lblPersonName" Runat="server" text=""></asp:label></TD>37
 <TD width="45%" height="30">
                                    <TD width="45%" height="30">38
 <asp:label id="JoinWorkDate" Width="80" Runat="server" text="参加革命日期:"></asp:label>
                                        <asp:label id="JoinWorkDate" Width="80" Runat="server" text="参加革命日期:"></asp:label>39
 <asp:label id="lblJoinWorkDate" Runat="server" text=""></asp:label></TD>
                                        <asp:label id="lblJoinWorkDate" Runat="server" text=""></asp:label></TD>40
 </TR>
                                </TR>41
 <TR>
                                <TR>42
 <TD width="45%" height="30">
                                    <TD width="45%" height="30">43
 <asp:label id="manageUnitName" Width="80" Runat="server" text="管理单位:"></asp:label>
                                        <asp:label id="manageUnitName" Width="80" Runat="server" text="管理单位:"></asp:label>44
 <asp:label id="lblmanageUnitName" Runat="server" text=""></asp:label></TD>
                                        <asp:label id="lblmanageUnitName" Runat="server" text=""></asp:label></TD>45
 <TD width="45%" height="30">
                                    <TD width="45%" height="30">46
 <asp:label id="subjectRelation" Width="80" Runat="server" text="隶属关系:"></asp:label>
                                        <asp:label id="subjectRelation" Width="80" Runat="server" text="隶属关系:"></asp:label>47
 <asp:label id="lblsubjectRelation" Runat="server" text=""></asp:label></TD>
                                        <asp:label id="lblsubjectRelation" Runat="server" text=""></asp:label></TD>48
 </TR>
                                </TR>49
 </TABLE>
                            </TABLE>50
 <TABLE id="table2" height="50%" width="100%" border="1">
                            <TABLE id="table2" height="50%" width="100%" border="1">51
 <TR>
                                <TR>52
 <TD>
                                    <TD>53
 <asp:panel id="PnlData" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"
                                        <asp:panel id="PnlData" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"54
 Height="100%">
                                            Height="100%">55
 <asp:DataGrid id="LgbDetailInfo" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"
                                            <asp:DataGrid id="LgbDetailInfo" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"56
 BorderWidth="1px" BackColor="White" CellPadding="4">
                                                BorderWidth="1px" BackColor="White" CellPadding="4">57
 <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
                                                <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>58
 <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
                                                <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>59
 <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
                                                <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>60
 <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
                                                <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>61
 <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
                                                <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>62
 </asp:DataGrid>
                                            </asp:DataGrid>63
 </asp:panel></TD>
                                        </asp:panel></TD>64
 </TR>
                                </TR>65
 </TABLE>
                            </TABLE>66
 <TABLE id="table3" height="20%" width="100%" border="1">
                            <TABLE id="table3" height="20%" width="100%" border="1">67
 <TR>
                                <TR>68
 <TD>
                                    <TD>69
 <asp:panel id="Panel3" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"
                                        <asp:panel id="Panel3" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"70
 Height="100%">中组部多记录信息集 <BR>
                                            Height="100%">中组部多记录信息集 <BR>71
 <asp:DataGrid id="A53InfoShow" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"
<asp:DataGrid id="A53InfoShow" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"72
 BorderWidth="1px" BackColor="White" CellPadding="4">
                                                BorderWidth="1px" BackColor="White" CellPadding="4">73
 <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
                                                <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>74
 <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
                                                <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>75
 <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
                                                <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>76
 <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
                                                <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>77
 <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
                                                <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>78
 </asp:DataGrid></asp:panel></TD>
                                            </asp:DataGrid></asp:panel></TD>79
 </TR>
                                </TR>80
 </TABLE>
                            </TABLE>81
 <TABLE id="table4" height="20%" width="100%" border="1">
                            <TABLE id="table4" height="20%" width="100%" border="1">82
 <TR>
                                <TR>83
 <TD>
                                    <TD>84
 <asp:panel id="Panel4" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"
                                        <asp:panel id="Panel4" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"85
 Height="100%">子女情况多记录信息集 <BR>
                                            Height="100%">子女情况多记录信息集 <BR>86
 <asp:DataGrid id="A70InfoShow" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"
<asp:DataGrid id="A70InfoShow" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"87
 BorderWidth="1px" BackColor="White" CellPadding="4">
                                                BorderWidth="1px" BackColor="White" CellPadding="4">88
 <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
                                                <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>89
 <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
                                                <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>90
 <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
                                                <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>91
 <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
                                                <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>92
 <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
                                                <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>93
 </asp:DataGrid></asp:panel></TD>
                                            </asp:DataGrid></asp:panel></TD>94
 </TR>
                                </TR>95
 </TABLE>
                            </TABLE>96
 <TABLE id="table5" height="20%" width="100%" border="1">
                            <TABLE id="table5" height="20%" width="100%" border="1">97
 <TR>
                                <TR>98
 <TD>
                                    <TD>99
 <asp:panel id="Panel5" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"
                                        <asp:panel id="Panel5" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"100
 Height="100%">非固定补贴情况多记录信息集 <BR>
                                            Height="100%">非固定补贴情况多记录信息集 <BR>101
 <asp:DataGrid id="A71InfoShow" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"
<asp:DataGrid id="A71InfoShow" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"102
 BorderWidth="1px" BackColor="White" CellPadding="4">
                                                BorderWidth="1px" BackColor="White" CellPadding="4">103
 <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
                                                <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>104
 <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
                                                <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>105
 <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
                                                <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>106
 <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
                                                <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>107
 <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
                                                <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>108
 </asp:DataGrid></asp:panel></TD>
                                            </asp:DataGrid></asp:panel></TD>109
 </TR>
                                </TR>110
 </TABLE>
                            </TABLE>111
 <TABLE id="table6" height="20%" width="100%" border="1">
                            <TABLE id="table6" height="20%" width="100%" border="1">112
 <TR>
                                <TR>113
 <TD>
                                    <TD>114
 <asp:panel id="Panel6" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"
                                        <asp:panel id="Panel6" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"115
 Height="100%">离休后奖惩情况多记录信息集 <BR>
                                            Height="100%">离休后奖惩情况多记录信息集 <BR>116
 <asp:DataGrid id="A72InfoShow" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"
<asp:DataGrid id="A72InfoShow" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"117
 BorderWidth="1px" BackColor="White" CellPadding="4">
                                                BorderWidth="1px" BackColor="White" CellPadding="4">118
 <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
                                                <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>119
 <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
                                                <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>120
 <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
                                                <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>121
 <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
                                                <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>122
 <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
                                                <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>123
 </asp:DataGrid></asp:panel></TD>
                                            </asp:DataGrid></asp:panel></TD>124
 </TR>
                                </TR>125
 </TABLE>
                            </TABLE>126
 <TABLE id="table7" height="20%" width="100%" border="1">
                            <TABLE id="table7" height="20%" width="100%" border="1">127
 <TR>
                                <TR>128
 <TD>
                                    <TD>129
 <asp:panel id="Panel7" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"
                                        <asp:panel id="Panel7" style="OVERFLOW: auto; POSITION: absolute" runat="server" Width="100%"130
 Height="100%">住院信息 <BR>
                                            Height="100%">住院信息 <BR>131
 <asp:DataGrid id="A73InfoShow" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"
<asp:DataGrid id="A73InfoShow" Width="100%" Runat="server" BorderStyle="None" BorderColor="#3366CC"132
 BorderWidth="1px" BackColor="White" CellPadding="4">
                                                BorderWidth="1px" BackColor="White" CellPadding="4">133
 <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
                                                <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>134
 <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
                                                <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>135
 <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
                                                <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>136
 <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
                                                <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>137
 <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
                                                <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>138
 </asp:DataGrid></asp:panel></TD>
                                            </asp:DataGrid></asp:panel></TD>139
 </TR>
                                </TR>140
 </TABLE>
                            </TABLE>141
 </asp:panel>
                        </asp:panel>142
 </td>
                    </td>143
 </tr>
                </tr>144
 </table>
            </table>145
 </form>
        </form>146
 </body>
    </body>147
 </HTML>
</HTML>148

关键部分是:
 <IMG height=80
<IMG height=80  src='ImagePage.aspx?PersonInfoID=<%=Request.QueryString["PersonInfoID"]%>'
            src='ImagePage.aspx?PersonInfoID=<%=Request.QueryString["PersonInfoID"]%>'  width=80>
            width=80>这里需要生成 ImagePage.aspx 页面
在 ImagePage.aspx 页面 编写代码如下:
 using System;
using System; using System.Collections;
using System.Collections; using System.ComponentModel;
using System.ComponentModel; using System.Data;
using System.Data; using System.Drawing;
using System.Drawing; using System.Web;
using System.Web; using System.Web.SessionState;
using System.Web.SessionState; using System.Web.UI;
using System.Web.UI; using System.Web.UI.WebControls;
using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;
using System.Web.UI.HtmlControls;
 using System.Data.SqlClient;
using System.Data.SqlClient; using System.IO;
using System.IO; using System.Drawing.Imaging;
using System.Drawing.Imaging;

 namespace Oceansoft.LGB.WEBUI.admin.search
namespace Oceansoft.LGB.WEBUI.admin.search {
{ /// <summary>
    /// <summary> /// ImagePage 的摘要说明。
    /// ImagePage 的摘要说明。 /// </summary>
    /// </summary> public class ImagePage : System.Web.UI.Page
    public class ImagePage : System.Web.UI.Page {
    { private void Page_Load(object sender, System.EventArgs e)
        private void Page_Load(object sender, System.EventArgs e) {
        { // 在此处放置用户代码以初始化页面
            // 在此处放置用户代码以初始化页面 //            if (Page.IsPostBack)
//            if (Page.IsPostBack) //            {
//            { Laod_Image();
                Laod_Image(); //            }
//            } //加载图象信息
             //加载图象信息 
             }
        } private void Laod_Image()
        private void Laod_Image() {
        { string PersonInfoID=Request.QueryString["PersonInfoID"];
            string PersonInfoID=Request.QueryString["PersonInfoID"]; string str_sqlGetImage="select A9901 from LGBPInfo where PersonInfoID='"+PersonInfoID+"'";
            string str_sqlGetImage="select A9901 from LGBPInfo where PersonInfoID='"+PersonInfoID+"'"; //图象处理
            //图象处理                 readImage(str_sqlGetImage);
            readImage(str_sqlGetImage); }
        } private void readImage(string str_sql)
        private void readImage(string str_sql) {
        { //            try
            //            try //            {
            //            { //                CommonInterface CIF=new CommonSql(strConn);
            //                CommonInterface CIF=new CommonSql(strConn); //                IDataReader dbRead=CIF.ExeForDtr(str_sql);
            //                IDataReader dbRead=CIF.ExeForDtr(str_sql);  //                if (dbRead.Read())
            //                if (dbRead.Read()) //                {
            //                { //                    Response.Clear();
            //                    Response.Clear(); //                    byte[] imageData =(byte[])dbRead["A9901"];
            //                    byte[] imageData =(byte[])dbRead["A9901"]; //                    Int32 imageSize = imageData.Length;
            //                    Int32 imageSize = imageData.Length; //                    Response.ContentType=dbRead["A9901"].ToString();
            //                    Response.ContentType=dbRead["A9901"].ToString(); //                    Response.OutputStream.Write(imageData, 0, imageSize);
            //                    Response.OutputStream.Write(imageData, 0, imageSize); //                    //Response.BinaryWrite(imageData);
            //                    //Response.BinaryWrite(imageData);                     //                    CIF.Close();
            //                    CIF.Close(); //                }
            //                } //                else
            //                else //                {
            //                { //                    CIF.Close();
            //                    CIF.Close(); //                }
            //                } //                //// Clear Response buffer
            //                //// Clear Response buffer //                Response.End();
            //                Response.End(); 
                 //            }
            //            } //            catch (Exception exe)
            //            catch (Exception exe) //            {
            //            { //                //throw exe;
            //                //throw exe; //            }
            //            } MemoryStream stream=new MemoryStream();
            MemoryStream stream=new MemoryStream(); string strConn=(string)Session["str_Conn"];//数据库连接字串
            string strConn=(string)Session["str_Conn"];//数据库连接字串 SqlConnection connection=new SqlConnection(strConn);
            SqlConnection connection=new SqlConnection(strConn); try
            try {
            { connection.Open();
                connection.Open(); SqlCommand command=new SqlCommand(str_sql,connection);
                SqlCommand command=new SqlCommand(str_sql,connection); byte[] image=(byte[])command.ExecuteScalar();
                byte[] image=(byte[])command.ExecuteScalar(); stream.Write(image,0,image.Length);
                stream.Write(image,0,image.Length); Bitmap bitImage=new Bitmap(stream);
                Bitmap bitImage=new Bitmap(stream); Response.ContentType="image/gif";
                Response.ContentType="image/gif";  bitImage.Save(Response.OutputStream,ImageFormat.Gif);
                bitImage.Save(Response.OutputStream,ImageFormat.Gif); 
                 }
            } catch
            catch {
            { //获得空白图片文件的路径 c:\inetpub\wwwroot\LGBWEB\admin\search
                //获得空白图片文件的路径 c:\inetpub\wwwroot\LGBWEB\admin\search string strblandImagePath= Server.MapPath("");
                string strblandImagePath= Server.MapPath(""); //c:\inetpub\wwwroot\LGBWEB\admin\
                //c:\inetpub\wwwroot\LGBWEB\admin\ strblandImagePath=strblandImagePath.Substring(0,strblandImagePath.Length-6)+"images\\blandImage.JPG";
                strblandImagePath=strblandImagePath.Substring(0,strblandImagePath.Length-6)+"images\\blandImage.JPG"; ///c:\inetpub\wwwroot\LGBWEB\admin\images\blandImage.JPG
                ///c:\inetpub\wwwroot\LGBWEB\admin\images\blandImage.JPG //strblandImagePath+="images\blandImage.JPG";
                //strblandImagePath+="images\blandImage.JPG";                     FileStream FileBlandImagestream=File.OpenRead(strblandImagePath);
                FileStream FileBlandImagestream=File.OpenRead(strblandImagePath); Bitmap bitImage=new Bitmap(FileBlandImagestream);
                Bitmap bitImage=new Bitmap(FileBlandImagestream); Response.ContentType="image/gif";
                Response.ContentType="image/gif";  bitImage.Save(Response.OutputStream,ImageFormat.Gif);
                bitImage.Save(Response.OutputStream,ImageFormat.Gif); }
            } finally
            finally {
            {             connection.Close();
                connection.Close(); stream.Close();
                stream.Close();                 }
            } }
        } 
         #region Web 窗体设计器生成的代码
        #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e)
        override protected void OnInit(EventArgs e) {
        { //
            // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 //
            // InitializeComponent();
            InitializeComponent(); base.OnInit(e);
            base.OnInit(e); }
        } 
         /// <summary>
        /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。
        /// 此方法的内容。 /// </summary>
        /// </summary> private void InitializeComponent()
        private void InitializeComponent() {
        {     this.Load += new System.EventHandler(this.Page_Load);
            this.Load += new System.EventHandler(this.Page_Load);
 }
        } #endregion
        #endregion }
    } }
}
运行通过
 
                    
                 
 

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号