Microsoft Access Database Management (ASP.NET VB)


This page discusses how to use ASP.NET VB (Visual Basic) 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 2015
  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.vb is given as follows:

    C:\ASP.NET-workspace\WebSite7\WebSite7\Default.aspx.vb
     Imports System
     Imports System.Data
     Imports System.Data.OleDb
     Imports System.Data.SqlClient
    
     Partial Class _Default
      Inherits System.Web.UI.Page
    
      Protected Sub Insert_Click( sender As Object, e As EventArgs ) Handles Insert.Click
       Dim conn As New OleDb.OleDbConnection( "Provider=Microsoft.ACE.OleDb.12.0;Data Source=" +
         Server.MapPath( "~/Access/Connect.accdb" ) )
       Dim sql As String = "INSERT INTO Contacts( FullName, City ) VALUES( @FullName, @City )"
       Dim cmd As New OleDb.OleDbCommand( sql, conn )
       cmd.Parameters.AddWithValue( "@FullName", FullName.Text )
       cmd.Parameters.AddWithValue( "@City", City.Text )
       conn.Open( )
       cmd.ExecuteNonQuery( )
       cmd.Dispose( )
       conn.Close( )
       Response.Redirect( "Result.aspx" )
      End Sub
    
     End Class

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

    C:\ASP.NET-workspace\WebSite7\WebSite7\Result.aspx.vb
     Partial Class Result
      Inherits System.Web.UI.Page
    
      Protected Sub Back_Click( sender As Object, e As EventArgs ) Handles Back.Click
       Response.Redirect( "Default.aspx" )
      End Sub
    
     End Class


  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)