Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
2.50/5 (3 votes)
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.
Posted
Updated 15-Oct-13 23:53pm
v2

Hello,

U can do one thing.

Use
C#
DataSet ds = new DataSet();
        ds.ReadXml("Path of xml file");


You can try this code by passing path of xml file that you want to upload to SQL server.

And after getting all data in dataset you can use loop to insert record.
 
Share this answer
 
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
 
Share this answer
 
Comments
Shubh Agrahari 15-Oct-13 8:47am    
but the main thing u forgetting dude that 1st u need to check the format of data and other many things..
 
Share this answer
 
Use OPENXML[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900