Results 1 to 5 of 5

Thread: [RESOLVED] Programmatically fetching table names from MS Access results in Nothing

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2022
    Posts
    39

    Resolved [RESOLVED] Programmatically fetching table names from MS Access results in Nothing

    For some reason I am getting Nothing for the table name that's pulled from an MS Access db. I just opened the file manually, and there is a Table named "log_returns", so why is this coming up as Nothing?

    The code below is used to add the found table names to a ListView. Although there is a table in a .mdb I am opening, there are no tables listed in the ListView, and the row count is zero. Is there an issue with the parameters being pulled from the dt?

    [CODE] Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data source =" & filename
    Dim cn As New OleDbConnection(ConnString)
    cn.Open()
    Dim restrictions() As String = New String(3) {}
    restrictions(3) = "Table"
    Dim userTables As DataTable = Nothing
    userTables = cn.GetSchema("Tables", restrictions)

    Dim ListView1 As New ListView

    For i = 0 To userTables.Rows.Count - 1
    Dim lvi As New ListViewItem(userTables.Rows(i)(2).ToString())
    ListView1.Items.Add(lvi)
    Next
    Last edited by pel11; Jul 27th, 2022 at 11:05 AM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,822

    Re: MS Access Table name is Nothing, but Table does exist

    There's a lot wrong here, both with the code and the question. I'll start with the main issue with the question and deal with the code issues later. You have shown us this line:
    vb.net Code:
    1. Dim selectedtable As String = Form_SelectAccessSQLTables.selectedtable
    but you have not shown us how you set selectedtable inside Form_SelectAccessSQLTables. For all we know, you never set it to anything and, based on the behaviour you describe, that appears to be the case. Presumably you need to set it based on the selection when someone makes one in the ListView. You need to show us that code because that's almost certainly where the actual issue is.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2022
    Posts
    39

    Re: MS Access Table name is Nothing, but Table does exist

    The question was revised, so that it only focuses on a count of zero for the number of rows in the dt.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,822

    Re: MS Access Table name is Nothing, but Table does exist

    I just used pretty much your exact code and I saw the expected table information. I suggest that you just bind the returned DataTable to a DataGridView, as I did, and see what you see:
    vb.net Code:
    1. Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data source =" & filename
    2. Dim cn As New OleDbConnection(ConnString)
    3. cn.Open()
    4. Dim restrictions() As String = New String(3) {}
    5. restrictions(3) = "Table"
    6. Dim userTables As DataTable = Nothing
    7. userTables = cn.GetSchema("Tables", restrictions)
    8.  
    9. DataGridView1.DataSource = userTables
    In fact, I suggest not using a ListView at all anyway, if you're using Details view. If you just want to display a list of table names then you can use a ListBox and you can use a DataGridView for one or more columns, either of which is easier and better than a ListView.

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2022
    Posts
    39

    Resolved Re: MS Access Table name is Nothing, but Table does exist

    SOLUTION: The table inside the .accdb file was an imported Excel workbook file (.xlsx) with an Excel icon, so I learned that those won't show up when trying to programmatically list the table. So I right-clicked on the Excel-based table and selected "Convert to Local Table" and then it was converted to an Access table. After this, the table is now visible and the row count in the dt is 1.
    Last edited by pel11; Jul 27th, 2022 at 11:06 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width