如何在asp.net中以编程方式将Excel数据传输到sqlserver表中 [英] How to transfer Excel data into sqlserver table programatically in asp.net

查看:134
本文介绍了如何在asp.net中以编程方式将Excel数据传输到sqlserver表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Experts,





我想通过UI将Excel文件上传到sqlserver 2008 r2表。

我在这里使用2个按钮。一种是浏览我成功从系统中选择文件的Excel文件。另一种是上传所选文件。



如何使用C#代码以编程方式将Excel文件上传到sql表。

Hello Experts,


I wan to upload an Excel file into sqlserver 2008 r2 table through UI.
I am using 2 buttons here. One is to browse the Excel file which i was successful to select the file from the system. And another is to upload the selected file.

How to do this to upload an Excel file into sql table programmatically using C# code.

推荐答案

使用 OPENXML [ ^ ]


访问此处.. 。



http://support.microsoft.com/kb/316005 [ ^ ]
visit here...

http://support.microsoft.com/kb/316005[^]


在此之前获取你的xml并在数据集中传递那个xml



插入到T_Profile_BuildingDetails(Category,SubCategory,Length,Width,Height,collegeCode)

选择

--Doc.col.value('TotalLandArea [1]','varchar(50)')为TotalLandArea

- ,Doc。 col.value('TotalConstructedA rea [1]','varchar(50)')作为TotalConstructedArea

- ,Doc.col.value('NoOfFloor [1]','varchar(50)')作为NoOfFloor

Doc.col.value('Category [1]','varchar(50)')作为类别

,Doc.col.value('SubCategory [1]', 'varchar(50)')作为SubCategory

,Doc.col.value('Length [1]','varchar(100)')作为长度

,Doc .col.value('Width [1]','varchar(50)')宽度

,Doc.col.value('Height [1]','varchar(15)')作为高度

,@ collegeCode
Before this get your xml and pass that xml in dataset

insert into T_Profile_BuildingDetails(Category,SubCategory,Length,Width,Height,collegeCode)
select
--Doc.col.value('TotalLandArea[1]','varchar(50)') as TotalLandArea
--,Doc.col.value('TotalConstructedArea[1]','varchar(50)') as TotalConstructedArea
--,Doc.col.value('NoOfFloor[1]','varchar(50)') as NoOfFloor
Doc.col.value('Category[1]','varchar(50)') as Category
,Doc.col.value('SubCategory[1]','varchar(50)') as SubCategory
,Doc.col.value('Length[1]','varchar(100)') as Length
,Doc.col.value('Width[1]','varchar(50)') as Width
,Doc.col.value('Height[1]','varchar(15)') as Height
,@collegeCode


这篇关于如何在asp.net中以编程方式将Excel数据传输到sqlserver表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆