Microsoft Access Database Management (ASP.NET C#)


  • Microsoft keeps updating its products and each version is slightly different from its previous version. The instructor is tired of updating his slides to keep up with Microsoft, but you should be able to tell the differences.

  • The Visual Studio 2019 in the classroom CEC205 only accepts 2000 or 2002-2003 Access database format .mdb. The .accdb format will crash the VS. Make sure that you use the .mdb format in case you will use the CEC205 to demonstrate your exercises.
This page discusses how to use ASP.NET C# programs to manage Microsoft Access databases.
  1. Check the Microsoft Access Database Help Pages.

  2. Start the Visual Studio Community.
  3. Check the ASP.NET Programming and select the following Windows options:
       Start ⇒ All Programs
             ⇒ Visual Studio 2017
  4. Create a Web Site.
  5. For example, create a web site at C:\ASP.NET-workspace\WebSite7\ .

  6. Use the Access to Build a Database and Tables.
  7. Check the Microsoft Access Database Management. Under the web site, create a folder such as C:\ASP.NET-workspace\WebSite7\WebSite7\Access\ to host the database used by the web site.




  8. Build the Web Interfaces.
  9. There are two user interfaces for this site, Default.aspx and Result.aspx, as follows:




  10. Complete the VB Programs.
  11. For how to program in ASP.NET, check the ASP.NET Quickstart Tutorial, which demonstrates selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. The source code of Default.aspx.cs is given as follows:

    C:\ASP.NET-workspace\WebSite7\WebSite7\Default.aspx.cs
     using System;
     using System.Data.OleDb;
    
     public partial class _Default : System.Web.UI.Page {
      protected void Insert_Click( Object sender, EventArgs e ) {
       String connString = "Provider=Microsoft.ACE.OleDb.12.0;Data Source=" +
         Server.MapPath( "Access\\Connect.accdb" ); 
       OleDbConnection conn = new OleDbConnection( connString );
       String sql = "INSERT INTO Contacts( FullName, City ) VALUES( @FullName, @City )";
       OleDbCommand cmd = new OleDbCommand( sql, conn );
       cmd.Parameters.AddWithValue( "@FullName", FullName.Text );
       cmd.Parameters.AddWithValue( "@City", City.Text );
       conn.Open( );
       cmd.ExecuteNonQuery( );
       conn.Close( );
       cmd.Dispose( );
       Response.Redirect( "Result.aspx" );
      }
     }

    The source code of Result.aspx.cs is given as follows:

    C:\ASP.NET-workspace\WebSite7\WebSite7\Result.aspx.cs
     using System;
    
     public partial class Result : System.Web.UI.Page {
      protected void Back_Click( Object sender, EventArgs e ) {
       Response.Redirect( "Default.aspx" );
      }
     }


  12. Build and Debug the Web Site.
  13. Build the web site by selecting the following options:
       Build ⇒ Build Web Site
    If the build is successful, close the Access and debug the web site by selecting the options:
       Debug ⇒ Start Without Debugging


    Default.aspx

    Insert



    Back


    Result.aspx

  14. Launch the Web Site the Next Time.
  15. Select the options:
       File ⇒ Open
            ⇒ Project/Solution...
            ⇒ Open (C:\ASP.NET-workspace\WebSite7\WebSite7.sln)