Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

An existing Access Database table issue

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
farrellthrasher
Asked:
farrellthrasher
  • 2
1 Solution
 
arif_eqbalCommented:
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
 
farrellthrasherAuthor Commented:
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
 
arif_eqbalCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now