how to get first row and column value from data table which contain value from excel sheet using c# to create dynamic table in sql server -
i had exported data excel file data table.what want take header of excel file , make dynamic table in sql database every time update new excel here code import data excel data table.
protected datatable dataexcel() { datatable dt = new system.data.datatable(); try { string filenname=@"c:\users\sani singh\documents\excel03.xls"; string sworkbook = "[sheet1$]"; string excelconnectionstring=@"provider=microsoft.jet.oledb.4.0;data source="+filenname+";extended properties='excel 8.0;hdr=yes;imex=1'"; oledbconnection oledbconn = new oledbconnection(excelconnectionstring); oledbconn.open(); oledbcommand oledbcmd = new oledbcommand(("select * " + sworkbook), oledbconn); dataset ds = new dataset(); oledbdataadapter sda = new oledbdataadapter(oledbcmd); sda.fill(ds); dt = ds.tables[0]; oledbconn.close(); } catch(exception ex) { response.write(ex); } return dt; }
Comments
Post a Comment