Anda di halaman 1dari 3

I m por t D 10/ 16/ 12 excel t o SQ L ser ver usi g C i ASP.

N - C at a f r om n # n ET odePr oj ct e

Articles Web Development ASP.NET General

Import Data from excel to SQL server using C# in ASP. NET


By Suraj S Koneri, 16 Dec 2011
4.27 (10 votes)

The Page having a FileUpload control and the Upload button, on selecting the Excel file user needs to click on Upload button to store the data to Server. Here we are treating the uploaded file as database hence we need to create OLEDB connection to this file, from this connection will be created and the data is fetched to C# as DataTable. '[Sheet1$]' is the Name of the Worksheet where requires data is present.
srn SucCnt =@Poie=irsf.C.LD.20Dt Suc="+ +";xedd tig oreosr "rvdrMcootAEOEB1.;aa ore' 'Etne Poete='xe 80HRYsIE='; rpris Ecl .;D=e;MX1" Oeboncincn=nwOeboncinSucCnt) lDCneto o e lDCneto(oreosr; srn qey="eet*fo [he1]; tig ur Slc rm Set$" Oebaadpe dt =nwOebaadpe(ur,cn; lDDtAatr aa e lDDtAatrqey o) dt.ildEcl; aaFl(txe)

From this code connection will be created for the Excel file and the data in Sheet1 will be dumped to the dtExcel of type DataTable. Note:'$' must be there after the worksheet name. Whole code for the same is here.
flNm =FlUla1Rsleletr(iepod.otdieFlNm) ieae iepod.eovCinUlFlUla1PseFl.ieae; itcut=0 n on ; DtCassaaotx cniq=nwDtCassaaotx(Dt Suc=evr aalseDtCnet oLn e aalseDtCnet"aa oresre nm;nta CtlgDtbs Nm;nertdScrt=re) aeIiil aao=aaae aeItgae euiytu"; ty r { DtTbedEcl=nwDtTbe) aaal txe e aaal(; srn SucCnt =@Poie=irsf.C.LD.20Dt Suc="+flNm + tig oreosr "rvdrMcootAEOEB1.;aa ore' ieae ";xeddPoete='xe 80HRYsIE='; 'Etne rpris Ecl .;D=e;MX1" Oeboncincn=nwOeboncinSucCnt) lDCneto o e lDCneto(oreosr; srn qey="eet*fo [he1]; tig ur Slc rm Set$" Oebaadpe dt =nwOebaadpe(ur,cn; lDDtAatr aa e lDDtAatrqey o) dt.ildEcl; aaFl(txe) fr(n i=0 i<dEclRw.on;i+ o it ; txe.osCut +) { ty r { cut+ cniqEeueomn(isr it tbenm vle( +dEclRw[] on = oLn.xctCmad"net no al ae aus" txe.osi
w w codepr oj ct . com / Ti s/ 300639/ I m por t - D a- f r om - excel t o- SQ L- ser ver - usi g- C w. e p at n shar p?di pl y=Pr i t s a n 1/ 3

I m por t D 10/ 16/ 12 excel t o SQ L ser ver usi g C i ASP. N - C at a f r om n # n ET odePr oj ct e

[]+""+dEclRw[]1 +"' +dEclRw[]2 +",+txe.osi[]""; 0 , txe.osi[] ," txe.osi[] '"dEclRw[]3+)) } cth(xeto e) ac Ecpin x { cniu; otne } } i (on = dEclRw.on) f cut = txe.osCut { <-ucs Msae-Sces esg-> } es le { <-alr Msae-Fiue esg-> } } cth(xeto e) ac Ecpin x { trwe; ho x } fnly ial { cniqDsoe) oLn.ips(; }

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

About the Author

Suraj S Koneri
India Member No Biography provided

Comments and Discussions


13 messages have been posted for this article Visit http://www.codeproject.com/Tips/300639/Import-Data-from-excel-to-SQL-server-using-Csharp to post and view comments on this article, or click here to get a print view with messages.
Permalink | Advertise | Privacy | Mobile Web02 | 2.6.121012.1 | Last Updated 16 Dec 2011
w w codepr oj ct . com / Ti s/ 300639/ I m por t - D a- f r om - excel t o- SQ L- ser ver - usi g- C w. e p at n shar p?di pl y=Pr i t s a n

Article Copyright 2011 by Suraj S Koneri Everything else Copyright CodeProject, 1999-2012
2/ 3

I m por t D 10/ 16/ 12 excel t o SQ L ser ver usi g C i ASP. N - C at a f r om n # n ET odePr oj ct e

Terms of Use

w w codepr oj ct . com / Ti s/ 300639/ I m por t - D a- f r om - excel t o- SQ L- ser ver - usi g- C w. e p at n shar p?di pl y=Pr i t s a n

3/ 3

Anda mungkin juga menyukai