Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: to all connection issue


Message #1 by "Dan Crandell" <dcrandell@r...> on Wed, 23 Oct 2002 12:59:51 -0500
I have this code and I can not get it to run against an access database?


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

<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="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
  String strConnection = "Provider=Microsoft.Jet.OleDb.4.0; data
source=C:\\7418BegASPNETdbCS\\datastores\\Northwind.mdb;";
  OleDbConnection objConnection = new OleDbConnection(strConnection);

  String strSQL = "SELECT SupplierID, CompanyName FROM Suppliers";
  OleDbCommand objCommand = new OleDbCommand(strSQL, objConnection);

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


  Return to Index