N - C at a f r om n # n ET odePr oj ct e
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
[]+""+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)
Suraj S Koneri
India Member No Biography provided
Article Copyright 2011 by Suraj S Koneri Everything else Copyright CodeProject, 1999-2012
2/ 3
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