Click here to Skip to main content
15,112,304 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.
Updated 16-Oct-13 0:53am

Before this get your xml and pass that xml in dataset

insert into T_Profile_BuildingDetails(Category,SubCategory,Length,Width,Height,collegeCode)
--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
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..

U can do one thing.

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.

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