473,811 Members | 2,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get Names of Tables in Database

How do I, in VB get the names of all the tables in an Access data bas

Also, how do I programatically get all the field names in a specific table

Much appreciated.
Nov 20 '05 #1
5 1479
Hi,

Add a reference to microsoft ado ext 2.8 for dll and security
and microsoft activex data objects 2.8 library in the com tab.

Imports System.Security
Imports System.Security .Permissions
Imports System.Runtime. InteropServices
Imports ADOX

<Assembly: SecurityPermiss ion(SecurityAct ion.RequestMini mum)>
<ComVisible(Fal se)> _
Module Module1

Sub Main()
Dim tbl As New Table
Dim cnn As New ADODB.Connectio n
Dim cat As New ADOX.Catalog
Dim cmd As New ADODB.Command

' Open the Connection
cnn.Open( _
"Provider='Micr osoft.Jet.OLEDB .4.0';" & _
"Data Source='Northwi nd.mdb';")

' Open the catalog
cat.ActiveConne ction = cnn

For Each tbl In cat.Tables
Dim col As ADOX.Column
For Each col In tbl.Columns
Console.WriteLi ne(String.Forma t("Table {0} Column Name {1}",
tbl.Name, col.Name))
Next
Next

cnn.Close()
End Sub

End Module
Ken
--------------------
"Gavin" <ga****@schiffy .com> wrote in message
news:51******** *************** ***********@mic rosoft.com...
How do I, in VB get the names of all the tables in an Access data base

Also, how do I programatically get all the field names in a specific
table.

Much appreciated.

Nov 20 '05 #2
Thanks
Nov 20 '05 #3
Dim Cnstr As String
Dim dc As DataRow
Dim i As Integer
Dim j As Integer

Cnstr = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source = C:\Program
Files\Microsoft Visual Studio\VB98\NWI ND.MDB"

Dim Con As OleDb.OleDbConn ection = New OleDb.OleDbConn ection(Cnstr)
Con.Open()

Dim DBTables As DataTable =
Con.GetOleDbSch emaTable(System .Data.OleDb.Ole DbSchemaGuid.Ta bles, New
Object() {Nothing, Nothing, Nothing, "TABLE"})

For i = 0 To DBTables.Column s.Count - 1

If DBTables.Column s(i).ToString = "TABLE_NAME " Then

For j = 0 To DBTables.Rows.C ount - 1

dc = DBTables.Rows(j )

Console.Out.Wri teLine(dc.Item( i))

Next

End If

Next i

Dim Da as OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter("Select * From
Products", Con)

Dim Tbl As new DataTable

da.Fill(Tbl)

For i = 0 To Tbl.Columns.Cou nt - 1

Console.Out.Wri teLine(tbl.Colu mns(i).ToString ())

Next

"Gavin" <ga****@schiffy .com> wrote in message
news:51******** *************** ***********@mic rosoft.com...
How do I, in VB get the names of all the tables in an Access data base

Also, how do I programatically get all the field names in a specific table.
Much appreciated.

Nov 20 '05 #4
Thanks for your Help

The statement: Imports ADOX - get error message ADOX cannot b found

Thanks
Nov 20 '05 #5
Have you added the reference? Right click on References in Solution
Explorer, Add Reference. Scroll down the Com list to find Microsoft ADO.
"gavin" <an*******@disc ussions.microso ft.com> wrote in message
news:22******** *************** ***********@mic rosoft.com...
Thanks for your Help.

The statement: Imports ADOX - get error message ADOX cannot b found.

Thanks

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1896
by: ewu | last post by:
Hello all, I got a chance to peak into a database system. Part of its design is rather unfamiliar to me. When I look at the diagram generated by SQL Server, there are many floating tables. Eventually it turns out that these many floating tables are actually not floating. Their table names relate to fields (as TableID) in other tables. In this case, you can get a handle to one of such tables by search TableID columns in other tables.
2
8677
by: Amy | last post by:
This is what I want to do: 1. Delete all tables in database with table names that ends with a number. 2. Leave all other tables in tact. 3. Table names are unknown. 4. Numbers attached to table names are unknown. 5. Unknown number of tables in database. For example:
3
1270
by: Ed L. | last post by:
I see that a newly created database in 8.0.0beta2 now has tables sql_sizing, sql_sizing_profiles, sql_packages, sql_features, sql_implementation_info, and sql_languages as part of the information schema. Given these are system tables, why are these tables not prefixed with 'pg_', as in 'pg_sql_sizing', etc? Ed
4
23911
by: Steven Smith | last post by:
Hello all, I have a vb6 (not .NET) program using MS Access as the backend. As part of an import form, I need to allow the user to select the table containing the data to be imported. How can I populate a combo with this information? Then, once this value is selected, how can I populate other combos with the column names of the selected table? Thanks,
5
5472
by: mail | last post by:
Urgent help needed! I moved an application from ASP+ACCESS to ASP+MS SQLSERVER and I have the following problem: If the join on two tables results on duplicate colum names (which appear in both tables) I could reference them by using: RECORDSET("TABLENAME.COLUMNAME")
3
1977
by: David C. Barber | last post by:
Using SQL Server 2000 and moving to a new computer. We did a full backup of the existing database to tape, brought up the new computer with a clean install using the same server name and IP address, and did a full restore. Not only were some permissions messed up, but Crystal Reports 10 and some Access Data Projects refused to run. I finally discovered while running an SP_WHO that the individual database names that we'd created (meaning...
11
10311
by: Tim Hunter | last post by:
Hi I am using WinXP and Access 2003 Is it possible to store the field names of a table in an array and then loop through the array and update the table using the field names stored in the array? I can't figure out the coding to accomplish this. I have an Excel application that is a monster and it has become too much to maintain and test. I didn't write it but i support it. I am trying to convert this application to Access and it is not as...
4
1614
by: | last post by:
Given an XML file (dataset.writexml), here is my output (simplified for this posting): <?xml version="1.0" standalone="yes"?> <NewDataSet> <Category> <CategoryId>80</CategoryId> <Category>MyCat</Category> </Category> </NewDataSet>
1
2135
by: tsorgi | last post by:
I'm writing a data conversion application to support a system migration. The code is reading formatted text files and loading them into MS SQL 2005 database tables. I wanted to call the existing INSERT stored procedures in the database to perform the update, yet I don't want to hard-code all the parameter names. Below is a bit of code that reads the imported data from the 'Data' DataTable, and prepares to insert it into the database table...
4
8882
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect the tables together with various queries using a unique id. My task is to generate reports from these tables dynamically. The user will select the data they want to see and the script will export a spreadsheet containing this data. I've got the...
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.