a universal class to complete import data from an excel file into a database
2004-02-03 21:25
696 查看
How can i do that?
two file
one is update data to database
first step
i will define two sesion to write the operating table and operating columns in server.
two step
tell the customer where and how many columns they can update.
列显示名称1:真实列名1#列显示名称1:真实列名1#列显示名称1:真实列名1
//get the data from excle
string strConn="Provider=Microsoft.Jet.OleDb.4.0;Data Source=d:\\收支表.XLS;Extended Properties=\"Excel 8.0;\"";
OleDbConnection conn=new OleDbConnection(strConn);
conn.Open();
OleDbDataAdapter da=new OleDbDataAdapter("select * from [Sheet1$]",conn);
DataSet ds=new DataSet();
//import data to a dataset
da.Fill(ds,“tablename“);
//define sql Dataadapter
define a dataadapter
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(query, conn);
adapter.Update(ds,“tablename“)
another is import data to database
two file
one is update data to database
first step
i will define two sesion to write the operating table and operating columns in server.
two step
tell the customer where and how many columns they can update.
列显示名称1:真实列名1#列显示名称1:真实列名1#列显示名称1:真实列名1
//get the data from excle
string strConn="Provider=Microsoft.Jet.OleDb.4.0;Data Source=d:\\收支表.XLS;Extended Properties=\"Excel 8.0;\"";
OleDbConnection conn=new OleDbConnection(strConn);
conn.Open();
OleDbDataAdapter da=new OleDbDataAdapter("select * from [Sheet1$]",conn);
DataSet ds=new DataSet();
//import data to a dataset
da.Fill(ds,“tablename“);
//define sql Dataadapter
define a dataadapter
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(query, conn);
adapter.Update(ds,“tablename“)
another is import data to database
相关文章推荐
- [转帖]ASP.NET服务器端异步Web方法
- 开天辟地第一帖
- SQL Server唯一约束的使用
- 用户登录后重定向的一种新方法
- WinRAR 简体中文版下载地址(有3721, CNNIC, 百度, 新浪免疫程序)
- ASP 中 Split 函数的实例
- DW+ASP 玩转动态二级菜单
- SMART POINTER(智能指针)
- 进销存软件之OO设计--中间层处理(二)
- 数据结构与算法(C#实现)系列-----前言
- 数字签名(java)
- 从GBA开始,步入ARM开发的殿堂(初学者入门篇)
- 通用查询组件设计
- 数据结构与算法(C#实现)系列---N叉树(二)
- 数据结构与算法(C#实现)系列---N叉树(一)
- 数据结构与算法(C#实现)系列---广义树(二)
- 数据结构与算法(C#实现)系列---广义树(一)
- 数据结构与算法(C#实现)系列---树(三)
- 数据结构与算法(C#实现)系列---树(二)
- 数据结构与算法(C#实现)系列---树(一)