Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示

最近捣鼓了一下,效果就是这样:
图1:
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示

图2:
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示

ImageFileUpload.aspx:

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="ImageFileUpload.aspx.cs"Inherits="ImageFileUpload"%>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<htmlxmlns="http://www.w3.org/1999/xhtml">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<headrunat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<title>图片保存和显示</title>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</head>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<body>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<formid="Form2"enctype="multipart/form-data"runat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableID="Table1"Runat="server"Width="39%"BorderWidth="1"BackColor="Beige">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableRowrunat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellColumnSpan="2"BackColor="Red"runat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:LabelID="Label1"Font-size="12px"ForeColor="White"font-bold="True"Runat="server"Text="添加"Font-Names="verdana"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TableRow>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableRowrunat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellHorizontalAlign="Right"runat="server"><asp:LabelID="Label2"Font-size="12px"Runat="server"Text="名字"Font-Names="verdana"/></asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellrunat="server"><asp:TextBoxid="txtPersonName"Runat="server"/></asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TableRow>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableRowrunat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellHorizontalAlign="Right"runat="server"><asp:LabelID="Label3"Font-size="12px"Runat="server"Text="Email"Font-Names="verdana"/></asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellrunat="server"><asp:TextBoxid="txtPersonEmail"Runat="server"/></asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TableRow>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableRowrunat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellHorizontalAlign="Right"runat="server"><asp:LabelID="Label4"Font-size="12px"Runat="server"Text="性别"Font-Names="verdana"/></asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellrunat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:RadioButtonGroupName="sex"Font-Size="12px"Text="男性"ID="sexMale"Runat="server" Checked="true"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:RadioButtonGroupName="sex"Font-Size="12px"Text="女性"ID="sexFeMale"Runat="server"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TableRow>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableRowrunat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellHorizontalAlign="Right"runat="server"><asp:LabelID="Label5"Font-size="12px"Runat="server"Text="生日"Font-Names="verdana"/></asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellrunat="server"><asp:TextBoxid="txtPersonDob"runat="server"/></asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TableRow>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableRowrunat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellHorizontalAlign="Right"runat="server"><asp:LabelID="Label6"Font-size="12px"Runat="server"Text="图片"Font-Names="verdana"/></asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellrunat="server"><inputtype="file"id="PersonImage"runat="server"/></asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TableRow>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableRowrunat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TableCellColumnSpan="2"HorizontalAlign="Center"runat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:ButtonID="Button1"Text="添加"OnClick="AddPerson"runat="server"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TableCell>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TableRow>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:Table>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<br/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<table>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tr>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdalign="left"valign="top"style="width:181px">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:LabelID="Label_Message"runat="server"Font-Size="10pt"></asp:Label></td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdstyle="width:7px">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdalign="left"style="width:18px"valign="top">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</tr>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tr>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdstyle="width:181px;"align="left"valign="top">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"CellPadding="4"DataKeyNames="PersonID"DataSourceID="SqlDataSource_SelectImage"ForeColor="#333333"OnSelectedIndexChanged="GridView1_SelectedIndexChanged"Font-Size="10pt"Width="200px"BackColor="#FFE0C0">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<FooterStyleBackColor="#507CD1"Font-Bold="True"ForeColor="White"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<Columns>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:TemplateFieldHeaderText="序号"InsertVisible="False"SortExpression="PersonID">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<EditItemTemplate>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:LabelID="Label1"runat="server"Text='<%#Eval("PersonID")%>'></asp:Label>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</EditItemTemplate>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<ItemTemplate>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:LabelID="Label1"runat="server"Text='<%#Bind("PersonID")%>'></asp:Label>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</ItemTemplate>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<HeaderStyleWidth="35px"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:TemplateField>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:BoundFieldDataField="PersonName"HeaderText="名字"SortExpression="PersonName"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:BoundFieldDataField="PersonImageType"HeaderText="图片类型"SortExpression="PersonImageType"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:CommandFieldShowSelectButton="True">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<ItemStyleWidth="30px"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:CommandField>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</Columns>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<RowStyleBackColor="#EFF3FB"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<EditRowStyleBackColor="#2461BF"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<SelectedRowStyleBackColor="#D1DDF1"Font-Bold="True"ForeColor="#333333"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<PagerStyleBackColor="#2461BF"ForeColor="White"HorizontalAlign="Center"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<HeaderStyleBackColor="Red"Font-Bold="True"ForeColor="White"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<AlternatingRowStyleBackColor="White"/>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</asp:GridView>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdstyle="width:7px;height:180px;">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdalign="left"style="width:18px;height:180px;"valign="top">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:ImageID="Image_Show"runat="server"/></td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</tr>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tr>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdstyle="width:181px">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdstyle="width:7px">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdstyle="width:18px">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</tr>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tr>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdstyle="width:181px;height:21px;">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdstyle="width:7px;height:21px;">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<tdstyle="width:18px;height:21px;">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</td>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</tr>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</table>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<asp:SqlDataSourceID="SqlDataSource_SelectImage"runat="server"ConnectionString="<%$ConnectionStrings:ImageSelect_ConnectionString%>"
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SelectCommand
="SELECTPersonID,PersonName,PersonImageTypeFROMPerson"></asp:SqlDataSource>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</form>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</body>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</html>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示

ImageFileUpload.aspx.cs:
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示usingSystem;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Data;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Configuration;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Collections;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web.Security;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web.UI;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web.UI.WebControls;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web.UI.WebControls.WebParts;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web.UI.HtmlControls;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Data.SqlClient;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.IO;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
publicpartialclassImageFileUpload:System.Web.UI.Page
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
protectedvoidPage_Load(objectsender,EventArgse)
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
protectedvoidAddPerson(objectsender,EventArgse)
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
intintImageSize;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
stringstrImageType;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示StreamImageStream;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示intImageSize
=PersonImage.PostedFile.ContentLength;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示ImageStream
=PersonImage.PostedFile.InputStream;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示strImageType
=PersonImage.PostedFile.ContentType;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Byte[]ImageContent
=newByte[intImageSize];
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
intintStatus;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示intStatus
=ImageStream.Read(ImageContent,0,intImageSize);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
//stringConnStr=System.Configuration.ConfigurationSettings.AppSettings["Lw_SqlConnectString"];
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
stringConnStr="DataSource=127.0.0.1;InitialCatalog=Pfrmis_TZXY;UserID=sa";
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SqlConnectionmyConnection
=newSqlConnection(ConnStr);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SqlCommandmyCommand
=newSqlCommand("sp_person_isp",myConnection);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myCommand.CommandType
=CommandType.StoredProcedure;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SqlParameterprmEmail
=newSqlParameter("@PersonEmail",SqlDbType.VarChar,255);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示prmEmail.Value
=txtPersonEmail.Text;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myCommand.Parameters.Add(prmEmail);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SqlParameterprmName
=newSqlParameter("@PersonName",SqlDbType.VarChar,255);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示prmName.Value
=txtPersonName.Text;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myCommand.Parameters.Add(prmName);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SqlParameterprmSex
=newSqlParameter("@PersonSex",SqlDbType.Char,1);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
if(sexMale.Checked)
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示prmSex.Value
="M";
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
else
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示prmSex.Value
="F";
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myCommand.Parameters.Add(prmSex);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SqlParameterprmPersonDOB
=newSqlParameter("@PersonDOB",SqlDbType.DateTime);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示prmPersonDOB.Value
=txtPersonDob.Text;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myCommand.Parameters.Add(prmPersonDOB);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SqlParameterprmPersonImage
=newSqlParameter("@PersonImage",SqlDbType.Image);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示prmPersonImage.Value
=ImageContent;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myCommand.Parameters.Add(prmPersonImage);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SqlParameterprmPersonImageType
=newSqlParameter("@PersonImageType",SqlDbType.VarChar,255);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示prmPersonImageType.Value
=strImageType;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myCommand.Parameters.Add(prmPersonImageType);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
try
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myConnection.Open();
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myCommand.ExecuteNonQuery();
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myConnection.Close();
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Response.Write(
"添加成功!");
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
catch(SqlExceptionSQLexc)
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Response.Write(
"插入失败,错误如下:"+SQLexc.ToString());
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
protectedvoidGridView1_SelectedIndexChanged(objectsender,EventArgse)
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
//Session["id"]="";
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Labellbl1;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示lbl1
=(Label)GridView1.SelectedRow.Cells[0].FindControl("Label1");
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Label_Message.Text
="你选择的图片是:"+lbl1.Text;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Session[
"id"]=lbl1.Text;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Image_Show.ImageUrl
="ImageShow.aspx";
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示

ImageShow.aspx:(显示图片)
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="ImageShow.aspx.cs"Inherits="ImageShow"%>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<htmlxmlns="http://www.w3.org/1999/xhtml">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<headrunat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<title>无标题页</title>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</head>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<body>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<formid="form1"runat="server">
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
<div>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</div>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</form>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</body>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
</html>
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示

ImageShow.aspx.cs:

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示usingSystem;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Data;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Configuration;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Collections;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web.Security;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web.UI;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web.UI.WebControls;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web.UI.WebControls.WebParts;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Web.UI.HtmlControls;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
usingSystem.Data.SqlClient;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
publicpartialclassImageShow:System.Web.UI.Page
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
protectedvoidPage_Load(objectsender,EventArgse)
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
//连接数据库的第一种方法
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
SqlConnectionmyConnection=newSqlConnection(ConfigurationManager.AppSettings["Lw_SqlConnectString"]);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
//连接数据库的第二种方法
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
//SqlConnectionmyConnection=newSqlConnection("DataSource=.;InitialCatalog=Tcis_shrl;UserId=sa;Password=;");
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
if(Session["id"]==null)
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
else
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
stringsql="SelectPersonImagefromPersonWherePersonID=";
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SqlCommandmyCommand
=newSqlCommand(sql+Session["id"].ToString().Trim(),myConnection);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
try
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myConnection.Open();
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示SqlDataReadermyDataReader;
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myDataReader
=myCommand.ExecuteReader(CommandBehavior.CloseConnection);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
if(myDataReader.Read())
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Response.Clear();
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
//Response.ContentType="image/pjpeg";//可有可无
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Response.BinaryWrite((byte[])myDataReader["PersonImage"]);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示myConnection.Close();
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
catch(SqlExceptionSQLexc)
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示{
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Response.Write(SQLexc);
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示Response.End();
Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示}

Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示


最后一个存储过程:
Drop Table Person

Go

Create Table Person

(

PersonID Int Identity,

PersonEmail Varchar(255),

PersonName Varchar(255),

PersonSex Char(1),

PersonDOB DateTime,

PersonImage Image,

PersonImageType Varchar(255)

)

Drop Proc sp_person_isp

Go

Create Proc sp_person_isp

@PersonEmail Varchar(255),

@PersonName Varchar(255),

@PersonSex Char(1),

@PersonDOB DateTime,

@PersonImage Image,

@PersonImageType Varchar(255)

As

Begin

Insert into Person

(PersonEmail, PersonName, PersonSex,

PersonDOB, PersonImage, PersonImageType)

Values

(@PersonEmail, @PersonName, @PersonSex,

@PersonDOB, @PersonImage, @PersonImageType)

End

Go