资源简介
一个Excel导入到数据库的Demo和一个winFrom的Excel的导入,简单好用。一个Excel导入到数据库的Demo和一个winFrom的Excel的导入,简单好用。一个Excel导入到数据库的Demo和一个winFrom的Excel的导入,简单好用。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using WebApplication1;
namespace excel
{
///
/// export 的摘要说明
///
public class export : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = “text/plain“;
HttpFileCollection httpFileCollection = context.Request.Files;
if (httpFileCollection.Count == 0)
{
context.Response.Write(“请选择你要上传的excel文件“);
context.Response.End();
}
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings[“ConnectionString“]?.ConnectionString;
if (string.IsNullOrWhiteSpace(connStr))
{
context.Response.Write(“数据库链接字符串没有配置“);
context.Response.End();
}
foreach (string name in httpFileCollection)
{
string path =context.Server.MapPath(“~“) + @“upload\“ + Guid.NewGuid() + httpFileCollection[name].FileName;
httpFileCollection[name].SaveAs(path);
var helper = new ExcelHelper(path);
DataTable dt = helper.ExcelToDataTable(“Sheet1“ true);
if (dt == null)
{
context.Response.Write(“上传的excel文件格式不对“);
context.Response.End();
}
//对手机号去重
DataTable newtable = dt.AsDataView().ToTable(true);
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
foreach (DataRow row in newtable.Rows)
{
string commandStr = “INSERT INTO t_stu_info(namephoneremark) VALUES(@name@phone@remark)“;
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = conn;
sqlCommand.CommandText = commandStr;
sqlCommand.CommandType = CommandType.Text;
SqlParameter[] sqlParameter ={
new SqlParameter(“@name“row[“name “]==null?““:row[“name “].ToString())
new SqlParameter(“@phone“row[“phone“]==null?““:row[“phone“].ToString())
new SqlParameter(“@remark“row[“remark“]==null?““:row[“remark“].ToString())
};
sqlCommand.Parameters.AddRange(sqlParameter);
sqlCommand.ExecuteNonQuery();
}
//using (SqlBulkCopy sqlBulkCopy = new System.Data.SqlClient.SqlBulkCopy(connStr SqlBulkCopyOptions.KeepIdentity | SqlBulkCopyOptions.UseInternalTran
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-03-06 09:09 excel\
目录 0 2019-03-06 09:07 excel\.vs\
目录 0 2019-03-06 09:07 excel\.vs\config\
文件 86088 2019-03-06 09:08 excel\.vs\config\applicationhost.config
目录 0 2019-03-06 09:07 excel\.vs\excel\
目录 0 2019-03-06 09:08 excel\.vs\excel\v15\
文件 75264 2019-03-06 10:46 excel\.vs\excel\v15\.suo
目录 0 2019-03-06 09:08 excel\.vs\excel\v15\Server\
目录 0 2019-03-06 09:08 excel\.vs\excel\v15\Server\sqlite3\
文件 0 2019-03-06 09:08 excel\.vs\excel\v15\Server\sqlite3\db.lock
文件 4096 2019-03-06 09:08 excel\.vs\excel\v15\Server\sqlite3\storage.ide
文件 32768 2019-03-06 10:29 excel\.vs\excel\v15\Server\sqlite3\storage.ide-shm
文件 1693352 2019-03-06 10:29 excel\.vs\excel\v15\Server\sqlite3\storage.ide-wal
目录 0 2019-03-06 09:07 excel\.vs\excel\v15\sqlite3\
文件 1060864 2019-03-06 09:03 excel\.vs\excel\v15\sqlite3\storage.ide
目录 0 2019-03-06 10:29 excel\excel\
目录 0 2019-03-06 09:13 excel\excel\Files\
文件 25177 2019-03-06 09:13 excel\excel\Files\2318bde6-f11d-48b3-bad4-74cdd363241d.xlsx
文件 78861 2019-03-06 09:13 excel\excel\Files\学生.xm
文件 89 2019-03-05 16:56 excel\excel\Global.asax
文件 335 2019-03-05 16:56 excel\excel\Global.asax.cs
目录 0 2019-03-06 09:07 excel\excel\ja
目录 0 2019-03-06 09:07 excel\excel\ja
目录 0 2019-03-06 09:07 excel\excel\ja
目录 0 2019-03-06 09:07 excel\excel\ja
文件 69524 2018-11-02 10:36 excel\excel\ja
文件 9885 2018-11-02 10:36 excel\excel\ja
目录 0 2019-03-06 09:07 excel\excel\ja
文件 1063 2018-11-02 10:36 excel\excel\ja
目录 0 2019-03-06 09:07 excel\excel\ja
目录 0 2019-03-06 09:07 excel\excel\ja
............此处省略382个文件信息
相关资源
- Essential C# 7.0.6th.Edition_epub_sources
- Tableau集成C#源码
- Winfom-帧动画Bad Apple
-
Visual C# and Databa
ses(15th) epub - 学生信息管理系统前台.net+后台c# 含数
- C#各种小游戏开发源代码
- wiki开源代码asp.net+sql
- asp.net 源码:微信公众号接口,微信企
- ReadShapeFile_test.rar
- 基于c#的串口发送图片代码
- HslCommunication C#的PLC通信类库源代码
- 学生选课系统C#代码
- c# wpf图片左右滑动的
- 快手安卓脚本雷电模拟器3.28 c#雷电多
- C# in Depth 中文第三版
- C#海康抓拍机Demo
- 基于C#.NET的员工考勤管理系统
- C# .net mvc 三层架构 增删改查
- C#课程设计源码
- 设计模式大作业游戏
- asp.net网上书店
-
Practical Databa
se Programming With Visual -
Beginning C# 5.0 Databa
ses(2nd) 无水印 - C#使用ffmpeg转换格式,截图,旋转
- C#写的背单词软件
- C# Mudbus开发
- C#简单的教材管理系统不含数据库
- C#二次开发CAD
- asp.net 图片管理系统(C#)
- C# 文件在线预览(word execl ppt Image t
评论
共有 条评论