Asp tutorial. net reads excel data and fills in dataset and gridview code
// Connection string
String ph = string. format ("upload \ {0}", name );
String xlspath = server. mappath (ph );
String connstr = "provider = microsoft. jet. oledb.4.0; "+" extended properties = "excel 8.0; hdr = no; imex = 1"; "+" data source = "+ xlspath;
String SQL _f = "select * from [{0}]";
Oledbconnection conn = null;
Oledbdataadapter da = null;
Datatable tblschema = null;
Ilist <string> tblnames = null;
// Initialize the connection and open it
Conn = new oledbconnection (connstr );
Conn. open ();
// Method 2
Connection string
Dim xlspath as string = server. mappath ("~ /App_data/excelfile.xls ") 'absolute physical path
Dim connstr as string = "provider = microsoft. jet. oledb.4.0; data source =" & xlspath & "; extended properties = excel 8.0 ;"
'Query statement
Dim SQL as string = "select * from [sheet1 $]"
Dim ds as dataset = new dataset ()
Dim da as oledb. oledbdataadapter = new oledb. oledbdataadapter (SQL, connstr)
Da. fill (ds) 'fill dataset
'Here we operate the data in dataset
'Output, bind data
Gridview1.datasource = ds. tables (0)
Gridview1.databind ()
The code above demonstrates the code bound to the gridview.