Solved

An existing Access Database table issue

Posted on 2006-07-06
5
185 Views
Last Modified: 2010-04-23
I have an existing Access database that has
tables (around 10). A routine that will open
any of the tables and allow the user close the
table when finished is needed.
0
Comment
Question by:farrellthrasher
  • 2
5 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
Comment Utility
Couldn't get what you want
What do you mean Close the Table ?
What would you do after opening the tabel, would you want to insert/update some data ?
0
 

Author Comment

by:farrellthrasher
Comment Utility
What I mean is that a routine that will allow me to access an Access database with 5 to 10 tables is needed. I would like to access any of the tables and access another table when I am finished inserting, updating or deleting data.
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 500 total points
Comment Utility
OK What I get from your query is that you want to list all the tables from your database
and then let the user select a table and work on it.
If he wants he can select another table and work on it and so on...

I am showing you the code for getting the table names from the access database showing them to user and based on the user selection showing records from the selected table to the user in a grid so that he can manipulate the data

>>>
Have a Listbox (LstTables) and a DataGridView(DGV) on your form then have this function

    Private Sub LoadTables()
        Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0......." 'Have your Connection string here
        Dim Cn As New OleDbConnection(ConStr)
        Cn.Open()
        Dim DT As DataTable = Cn.GetSchema("Tables")
        For Each dr As DataRow In DT.Rows
            If dr("TABLE_TYPE").ToString.ToUpper = "TABLE" Then LstTables.Items.Add(dr("TABLE_NAME").ToString.TrimEnd("$"))
        Next
        Cn.Close()
    End Sub

Call this function from say your Form_Load,

Also have this function to show data in Grid

    Private Sub LoadGrid(ByVal TblName As String)
        Dim Qry As String = String.Format("Select * from {0}", TblName)
        Dim DA As New OleDbDataAdapter(Qry, ConStr)
        Dim DT As New DataTable
        DA.Fill(DT)
        DGV.DataSource = DT
    End Sub

Select tables in the Listbox and you will see data populated in the Grid
This code however does not show you how to edit/update etc. the database table, you can find abundant help on the net for Updating/Inserting data into database table from a grid.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now