Asp tutorial. net how to obtain the excel worksheet data and Connection Method
C # how to read an excel Data Table
<% @ Page Language = "C #" %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. OleDb" %>
<Script runat = "server">
Void Page_Load (object sender, EventArgs e ){
String ConnectionString = @ "Provider = Microsoft. Jet. OLEDB.4.0; Data Source = C: Yourspreadsheet.xls; Extended Properties =" "Excel 8.0; HDR = Yes "";";
String CommandText = "select * from [Book $]";
OleDbConnection myConnection = new OleDbConnection (ConnectionString );
OleDbCommand myCommand = new OleDbCommand (CommandText, myConnection );
MyConnection. Open ();
DataGrid1.DataSource = myCommand. ExecuteReader (CommandBehavior. CloseConnection );
DataGrid1.DataBind ();
MyConnection. Close ();
}
</Script>
<Html>
<Head>
</Head>
<Body style = "FONT-FAMILY: arial">
<H2> Simple Data Report
</H2>
<Hr size = "1"/>
<Form runat = "server">
<Asp: datagrid id = "DataGrid1" runat = "server" EnableViewState = "False" ForeColor = "Black" BackColor = "White" CellPadding = "3" GridLines = "None" CellSpacing = "1 ">
<HeaderStyle font-bold = "True" forecolor = "white" backcolor = "# 4A3C8C"> </HeaderStyle>
<ItemStyle backcolor = "# DEDFDE"> </ItemStyle>
</Asp: datagrid>
</Form>
</Body>
</Html>
How to read excel Data Using vb.net
<% @ Import namespace = "System. Data" %>
<% @ Import namespace = "System. Data. OleDb" %>
<Html>
<Head>
<Title> Reading from an Excel Workbook </title>
</Head>
<Body>
<H3> Reading from an Excel Workbook </H3>
<Asp: DataGrid id = "dgInventory" runat = "server"/>
</Body>
</Html>
<Script language = "VB" runat = "server">
Sub Page_Load (Source As Object, E As EventArgs)
Dim strConnection As String = "Provider = Microsoft. Jet. OleDb.4.0 ;"&_
"Data source = C: yourExcellFileName.xls ;"&_
"Extended Properties = Excel 8.0 ;"
Dim objConnection As New OleDbConnection (strConnection)
Dim strSQL As String = "SELECT * FROM Items WHERE Source = 'Dell '"
Dim objCommand As New OleDbCommand (strSQL, objConnection)
ObjConnection. Open ()
DgInventory. DataSource = objCommand. ExecuteReader ()
DgInventory. DataBind ()
ObjConnection. Close ()
End Sub
</Script>