Connecting to an Access Database : OleDbConnection « ADO.net Database « ASP.NET Tutorial






<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.OleDb" %>
<%@ Page debug="true" %>

<html>
  <head>
    <title>Connecting to an Access Database</title>
  </head>

  <body>
    <H3>Connecting to an Access Database</H3>
    <asp:DataGrid id="dgSuppliers" 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:\northwind.mdb;"
  Dim objConnection As New OleDbConnection(strConnection)

  Dim strSQL As String = "SELECT SupplierID, CompanyName " & _
                         "FROM Suppliers;"
  Dim objCommand As New OleDbCommand(strSQL, objConnection)

  objConnection.Open()
  dgSuppliers.DataSource = objCommand.ExecuteReader()
  dgSuppliers.DataBind()
  objConnection.Close()
End Sub
</script>








18.10.OleDbConnection
18.10.1.Properties of OleDbConnection
18.10.2.Connecting to an Access Database