- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
将Excel数据快速大批量导入数据库的代码(Quickly import the Excel data into the database code)
将Excel数据快速大批量导入数据库的代码(Quickly import the Excel data into the database code)
Quickly import the Excel data into the database code
Classification: net 2011-09-09-09-423 reading review (0) collecting reports
The two ways to import data from EXCEL into SQL SERVER.
In the program, use ADO.NET. The code is as follows:
/ / connection string
String strConn = Provider = Microsoft. ;
OleDbConnection conn = new OleDbConnection (strConn);
Conn. The Open ();
DataTable dtSchema = conn. GetOleDbSchemaTable (OleDbSchemaGuid. Tables, new object [] {null, null, null, TABLE});
DataSet ds = new DataSet ();
/ / an EXCEL file may have multiple worksheets, traversing them
Foreach (DataRow Dr In dtschema.rows)
{
String table = Dr [r]. TABLE_NAME ToString ();
String strExcel = SELECT * FROM [ + table +];
Ds. Tables. The Add (table);
OleDbDataAdapter myCommand = new OleDbDataAdapter (strExcel, conn);
MyCommand. The Fill (ds, table);
}
Conn. Close ();
That way, the data is hidden in the DataSet.
In this way, the database machine does not need to be equipped with EXCEL.
2. In the query analyzer, write the SQL statement directly:
If you import data to an existing table, use it
INSERT INTO table SELECT * FROM OPENROWSET ( MICROSOFT. JET. Oledb.4.0
, Excel 5.0; HDR = YES; The DATABASE = c: \ test. XLS sheet1 $)
In the form of
If you import data and add tables, use
SELECT * INTO table FROM OPENROWSET ( MICROSOFT. JET. Oledb.4.0
, Excel 5.0; HDR = YES; The DATABASE = c: \ test. XLS sheet1 $)
In the form.
The above statement is to read all the columns in the SHEET1 worksheet in EXCEL file, and if you want only the partial columns, you can
INSERT INTO table (a1, a2, a3) SELECT a1, a2, a3 FROM OPENROWSET ( MICROSOFT. JET. Oledb.4.0
, Excel 5.0; HDR = YES; The DATABASE = c: \ test. XLS sheet1 $)
You can actually use OPENROWSET ( MICROSOFT.
, Excel 5.0; HDR = YES; DATABASE = c: \ test.xls, sheet1 $) as a table, for example, I wrote a sentence like this:
INSERT INTO eval_channel_employee (channel, emp
您可能关注的文档
- 农村小水电站的设计(The design of small hydropower stations in rural areas).doc
- 农大测量学答案2(The answer to the agricultural survey is 2).doc
- 冬季幼儿常见病4——麻疹(Winter childhood common disease 4 - measles).doc
- 农民专业合作社示范社创建标准(The farmer specialized cooperative model society creates the standard).doc
- 几何知识典型应用题(Geometric knowledge is a typical application problem).doc
- 几大硬盘品牌介绍(Several hard disk brand introduction).doc
- 几乎没人逃得过的超准思维定向测试!(Almost no one escapes the super-quasi-mental orientation test!).doc
- 凤凰卫视节目形式论文(Phoenix TV program form paper).doc
- 几种处理方式对皂荚直播造林地微环境和出苗率的影响(The effects of several treatment methods on the microenvironment and seedling rate of the live woodland were broadcast live).doc
- 凤头50例(Crested 50 cases).doc
- 小P语录(Small P sayings).doc
- 将CAD图形导入Coreldraw的实用方法(A practical method to import CAD graphics into Coreldraw).doc
- 小功率调频发射机(Small power FM transmitter).doc
- 小坪隧道膨胀岩地段的施工(Construction of the expansion rock section of the small flat tunnel).doc
- 小学奥数知识要点目录(A catalogue of the knowledge points of primary schools).doc
- 小学数学(奥数)(Primary school mathematics (Olympic number)).doc
- 小学教学大纲(Primary school syllabus).doc
- 小学数学应用题常用公式大全(Elementary school mathematics should use the general formula of the general formula).doc
- 小学数学知识点(Elementary school math).doc
- 小学数学四年级《线段、射线、直线》教学设计与检测(The teaching design and testing of fourth-grade mathematics of primary school, line segment, ray and line).doc
文档评论(0)