Read the data in the Excel file into the DataGrid

xiaoxiao2021-03-06  104

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.ui.WebControls; use system.web.ui.htmlcontrols;

Summary description of Namespace Excel {///

/// WebForm1. /// public class WebForm1: System.Web.UI.Page {protected System.Web.UI.WebControls.DataGrid mygrid; private void Page_Load (object sender, System.EventArgs e) {// Here placed User code Try {if (! ISpostback) {by (! Ispostback) {MyGrid.DataSource = CreateDataSource ();}} catch (exception ex);}}.

} Private dataset createDataSource () {string strconn; strconn = "provider = microsoft.jet.Oledb.4.0;" "data source = c: //inetpub//wwwroot//excel//a.xls;" "extended Properties = Excel 8.0; "; OleDbConnection conn = new OleDbConnection (strConn); OleDbDataAdapter myCommand = new OleDbDataAdapter (" SELECT * FROM [ContactList $] ", strConn); DataSet myDataSet = new DataSet (); myCommand.Fill (myDataSet); Return mydataset;

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private () {this.load = new system.eventhandler (this.page_load);

} #Endregion}}}

转载请注明原文地址:https://www.9cbs.com/read-100504.html

New Post(0)