|
-
Jul 25th, 2022, 05:50 PM
#1
Thread Starter
Lively Member
[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.
-
Jul 25th, 2022, 08:50 PM
#2
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:
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.
-
Jul 26th, 2022, 11:23 PM
#3
Thread Starter
Lively Member
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.
-
Jul 27th, 2022, 12:01 AM
#4
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:
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)
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.
-
Jul 27th, 2022, 10:54 AM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|