.NET(C#) EXCEL导入数据库 并显示在本页面 DEM导入

本文详细介绍了如何使用C#在.NET环境中实现从Excel文件导入数据到数据库,同时将导入的数据展示在网页上。通过上传Excel文件,将其保存到服务器,然后读取文件内容填充到DataTable,最终将数据存储到数据库中,并进行数据绑定以在页面显示。
摘要由CSDN通过智能技术生成

本文思路是这样的 EXCEL获取之后保存在服务器上 然后再通过保存的路径读取EXCEL到datatable中 达成导入数据库的目的 

这里是 前台页面body里的代码 

<body>
<form name="form1"  runat="server" >
 <TABLE class="tableCss"  style=" margin-top:10px;" cellSpacing=1 cellPadding=0 width="85%" align=center border=0 >
  <TBODY>
  <tr><td style=" height:30px; text-align:left; color:Red;">选择EXCEL文件上传(文件后缀名必须为 .xls )</td></tr>
   <TR>
    	
		<TD  class="row_search"  style=" margin-top:10px;" height="35" valign="top">
        <div style=" display:none">
    <asp:Button ID="readFromDB" runat="server"  Text="从数据库读取数据" /> 
     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" Font-Names="Arial" Font-Size="12px" GridLines="Horizontal" RowStyle-HorizontalAlign="Center" Width="98%">                  
     <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /> <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Center" />                  
     <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />                  
     <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />                  
     <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" HorizontalAlign="Center" />                  
     <AlternatingRowStyle BackColor="#F7F7F7" /> </asp:GridView> </div>                
    <input type="file" name="upload"  id="upload" runat="server" />                
     <asp:Button ID="Import" runat="server" OnClick="Import_Click" Text="导入" />                 
     
	
		</TD>

	</TR>

	</TBODY></TABLE>
    <table class="tableCss" cellspacing="1" cellpadding="0" width="85%" align="center" border="0" >
    <tr><td class="highRow" colspan="15" style=" text-align:left;">

</td></tr>
  
   <tr>

    	
    	<td class="highRow">序列号</td>
    	
    	
    	<td class="highRow">申请时间</td>
    	
    	<td class="highRow">姓名</td>
    	<td class="highRow">用户类型</td>
    	<td class="highRow">地址</td>
    	
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值