CSharp Reading From Excel Workbook (Vb.Net) – ADO.Net Database

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

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.