<%@ 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>
|