当前位置导航:炫浪网>>网络学院>>网页制作>>ASP.NET教程

上传文件到数据库并从数据库读出

  老是找不到合适的数据库上传下载的,从网上找了一些代码,改写了个可以直接使用的版本!

  代码

  AttachmentId    bigint    Unchecked

  AttachmentName    nvarchar(50)    Unchecked

  AgencyName    nvarchar(50)    Checked

  ClassName    nvarchar(255)    Checked

  TypeName    nvarchar(50)    Checked

  Image    image    Checked

  Flag    int    Checked

  Notes    text    Checked

  Unchecked

  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Attachment.aspx.cs" Inherits="hrootCIS.DataShow.Types.NewNavigator.Attachment" %>

  <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="http://www.w3.org/1999/xhtml" >

  <head id="Head1" runat="server">

  <title>附件信息</title>

  <link href ="http://www.cnblogs.com/../Styles/AjaxTookitStyle.css" type="text/css" rel="stylesheet" />

  </head>

  <body>

  <form id="form1" runat="server">

  <div style="height: 1882px; width: 1200px">

  <asp:ScriptManager ID="ScriptManager1" runat="server">

  </asp:ScriptManager>

  <cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0"

  Height="1616px" >

  <cc1:TabPanel runat="server" HeaderText="添加附件信息" ID="TabPanel1">

  <HeaderTemplate>

  添加附件信息

  </HeaderTemplate>

  <ContentTemplate>

  <div>

  <asp:Label ID="lblPoistion" runat="server" Text="附件:"></asp:Label>

  <input id="UpFile" runat="server" name="File1"

  type="file" /><br />

  <br />

  <br />

  <table>

  <tr>

  <td>选择公司:</td>

  <td><asp:DropDownList ID="dplAgencyA" runat="server"

  DataSourceID="SqlDataSourceAgencyA" DataTextField="AgencyName"

  DataValueField="Agencyid"></asp:DropDownList><asp:SqlDataSource ID="SqlDataSourceAgencyA" runat="server"

  ConnectionString="<%$ ConnectionStrings:mvcNewsConnectionString %>"

  SelectCommand="SELECT * FROM [Agency]"></asp:SqlDataSource></td></tr>

  <tr>

  <td>附件所属类别:</td>

  <td> <asp:DropDownList ID="dplClass" runat="server">

  <asp:ListItem>企业研究报告</asp:ListItem>

  <asp:ListItem>广告投放信息</asp:ListItem>

  <asp:ListItem>媒体曝光信息</asp:ListItem>

  <asp:ListItem>行业调研报告</asp:ListItem>

  </asp:DropDownList>

  </td>

  </tr>

  <tr>

  <td>附件简介</td>

  <td>

  <asp:TextBox ID="txtNotes" runat="server" Height="81px" TextMode="MultiLine"

  Width="273px"></asp:TextBox>  </td>

  </tr>

  </table>

  <asp:Button ID="btnUpLoad" runat="server" Text="上传附件"

  onclick="btnUpLoad_Click" />

  </div>

  </ContentTemplate>

  </cc1:TabPanel>

  <cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="管理">

  <HeaderTemplate >

  管理附件信息

  </HeaderTemplate>

  <ContentTemplate >

  <table cellpadding="0" cellspacing="0" style="height: 30px" width="98%"><tr><td><asp:DropDownList ID="DropDownList1" runat="server"

  DataSourceID="SqlDataSourceAgencyB" DataTextField="AgencyName"

  DataValueField="Agencyid"></asp:DropDownList><asp:SqlDataSource ID="SqlDataSourceAgencyB" runat="server"

  ConnectionString="<%$ ConnectionStrings:mvcNewsConnectionString %>"

  SelectCommand="SELECT * FROM [Agency]"></asp:SqlDataSource></td></tr><tr><td>

  <asp:Button

  ID="BtnShowAttachment" runat="server" Text="显示所选公司的附件信息"

  onclick="BtnShowAttachment_Click" BorderStyle="Outset"

  BorderWidth="1px" /></td></tr><tr><td align="center"><asp:GridView ID="gdvAttachment" runat="server" AutoGenerateColumns="False"

  Width="400px" CellPadding="4" ForeColor="#333333" GridLines="None"><AlternatingRowStyle BackColor="White" /><Columns><asp:TemplateField

  HeaderText="ID" Visible="False"><ItemTemplate><asp:Label ID="lblId"

  runat="server" Text="<%#Bind('AttachmentId') %>"></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateField><ItemTemplate><%#Eval("AttachmentName")%></a></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="选项"><ItemTemplate><asp:CheckBox ID="chkDelete" runat="server" /></ItemTemplate></asp:TemplateField><asp:TemplateField></asp:TemplateField></Columns><EditRowStyle BackColor="#2461BF" /><FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /><HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /><PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /><RowStyle BackColor="#EFF3FB" /><SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /></asp:GridView></td></tr><table><tr><td><asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" Text="删除" /></td></tr></table></table>

  </ContentTemplate>

  </cc1:TabPanel>

  <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="下载附件">

  <HeaderTemplate >

  下载附件

  </HeaderTemplate>

  <ContentTemplate >

  <asp:GridView ID="gdvAttachmentA" runat="server" AutoGenerateColumns="False"

  DataSourceID="SqlDataSourceAttachment"

  onrowcommand="gdvAttachmentA_RowCommand" DataKeyNames="AttachmentId">

  <Columns >

  <asp:BoundField DataField="AttachmentName" HeaderText="文件名称"

  SortExpression="AttachmentName" />

  <asp:BoundField DataField="ClassName" HeaderText="ClassName"

  SortExpression="ClassName" />

  <asp:TemplateField>

  <ItemTemplate>

  <asp:LinkButton ID="lbtnDownload" runat="server" CommandName="download" CommandArgument='<%#Eval("AttachmentName") %>'>下载</asp:LinkButton>

  </ItemTemplate>

  </asp:TemplateField>

  </Columns>

  </asp:GridView>

  <asp:SqlDataSource ID="SqlDataSourceAttachment" runat="server"

  ConnectionString="<%$ ConnectionStrings:mvcNewsConnectionString %>"

  SelectCommand="SELECT AttachmentId,AttachmentName,ClassName FROM [Attachment]"></asp:SqlDataSource>

  </ContentTemplate>

  </cc1:TabPanel>

  </cc1:TabContainer>

  </div>

  </form>

  </body>

  </html>

相关内容
赞助商链接