Using an Excel file as the data source of the DataGrid is very simple. Once the data is loaded in, you can save the data to SQL Server or XML. We only need to simply use ole db provider to access the Excel file and then return dataset.
<% @ Page Language = "C #" DEBUG = "true" %> <% @ import namespace = "system. data "%> <% @ import namespace =" system. data. oledb "%> <SCRIPT runat =" server "> private dataset createdatasource () {string strconn; strconn =" provider = Microsoft. jet. oledb.4.0; "+" Data Source = C :\\ Inetpub \ wwwroot \ contacts.xls; "+" extended properties = Excel 8.0; "; oledbconnection conn = new oledbconnection (strconn ); oledbdataadapter mycommand = N EW oledbdataadapter ("select * from [contactlist $]", strconn); dataset mydataset = new dataset (); mycommand. fill (mydataset); Return mydataset;} public void page_load (Object sender, eventargs e) {If (! Ispostback) {mygrid. datasource = createdatasource (); mygrid. databind () ;}</SCRIPT> <center> <form runat = "server"> <asp: dataGrid runat = "server" autogeneratecolumns = "false" width = "500" id = "mygrid">