QuestionQuestion

Create an Access database with the following information about 12 or more of your fellow club members on campus or in the community: first name, last name, address, city, state, zip, and age. Create a form that uses a ComboBox object for last names. Compute and display the average age of your club members. Use an image and allow users to add and delete members from the database.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

Imports System.Text.RegularExpressions

Public Class Form1

    ''' <summary>
    ''' connection string
    ''' Club.accdb is in Debug folder
    ''' </summary>
    Dim strPath As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Club.accdb"

    ''' <summary>
    ''' run when the form is loaded
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       Update_All()

    End Sub

    ''' <summary>
    ''' update the form
    ''' </summary>
    Private Sub Update_All()
       Combobox_Update()
       Dataset_Update()
       Label_Update()
    End Sub

    ''' <summary>
    ''' update the dataset
    ''' </summary>
    Private Sub Dataset_Update()
       If cbLastName.Items.Count > 0 Then
            ' get the name on the combo box
            Dim last_name = cbLastName.SelectedItem.ToString
            ' query the database
            Dim str As String = "SELECT * FROM member where last_name = " & Chr(34) & last_name & Chr(34)
            Dim da As OleDb.OleDbDataAdapter = query(str)
            Dim dt As New DataTable
            da.Fill(dt)
            ' put result on screen
            DataGridView1.DataSource = dt
       Else
            ' empty the dataset
            DataGridView1.DataSource = Nothing
       End If

    End Sub

    ''' <summary>
    ''' update list of last name in the combo box
    ''' </summary>
    Private Sub Combobox_Update()
       Dim row As System.Data.DataRow
       Dim Count As Integer

       ' query the database
       Dim str As String = "SELECT last_name FROM member"
       Dim ds As New DataSet
       Dim da As OleDb.OleDbDataAdapter = query(str)
       da.Fill(ds, "member")
       Count = ds.Tables("member").Rows.Count

       ' push data to the box
       Dim index As Integer = 0

       cbLastName.Items.Clear()

       While index < Count 'loop through for each row, add it to the datagridview

            row = ds.Tables("member").Rows.Item(index)
            cbLastName.Items.Add(row.Item(0))
            index = index + 1
       End While

       ' set default selected last name
       If cbLastName.Items.Count > 0 Then
            cbLastName.SelectedIndex = 0
       Else
            cbLastName.Text = ""
       End If
    End Sub

    ''' <summary>
    ''' update label of average age
    ''' </summary>
    Private Sub Label_Update()
       Dim row As System.Data.DataRow

       ' querey the database
       Dim str As String = "SELECT avg(age) FROM member"
       Dim ds As New DataSet
       Dim da As OleDb.OleDbDataAdapter = query(str)
       da.Fill(ds, "member")

       ' put data on screen
       Try
            row = ds.Tables("member").Rows.Item(0)
            lblAge.Text = row.Item(0)
       Catch ex As Exception
            lblAge.Text = 0
       End Try

    End Sub

    ''' <summary>
    ''' connect and run a query
    ''' </summary>...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$58.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Visual Basic Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats