• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How to get fields name from a table using Java/VB6/VB.NET/C# ?

larva

Member
Hi,

How can I get fields name from a table using Java/VB6/VB.NET/C# and display in a list box ? Thanks !

regards,
Larva
 
As far as VB6 is concerned...

Open a record set with an SQL command like "SELECT DISTINCT abc from xyz"

Then loop through the record set until it is EOF and add the items to the listbox.

Do While Not recordset.EOF
ListBox.AddItem recordset.Fields("abc")
recordset.MoveNext
Loop

I hope that helps.
 
Hi,

I don't want to get the data inside the column. I want the name of the column. Thanks !

----------------------------------------
Name | ID |
-----------------------------------------
Larva 1000

and I want to get the "Name" and "ID", not the data.

regards,
Larva
 
Hi,

If lets say I don't know how many column and the column name inside a table, how can I use Java/VB6/VB.NET to list all of them out into a listbox or other ? Thanks !

regards,
Larva
 
In vb6:

'-- First you need to create a connection to your DB:

Dim Conn
Set Conn = CreateObject("ADODB.Connection")
Conn.Open "DSN=MyDSN", "Username", "Password" [, options]

'-- Second, create a recordset that selects all of the fields, you only need one record though.

Dim rs
Set rs = CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM MyTable WHERE ID=1", Conn, 1

'--- Third, Set the listbox (list1) value by looping through the field names list:
Dim objField, i
i = 0
For Each objField in rs.Fields
     List1.AddItem objField.Name, i
     i = i + 1
Next
 
Hi Beau6183,

Thanks a lot for your info. How about if I wanna display all the tables name available in my database into the listbox ? Thank you !

regards,
Larva
 
Originally posted by: larva
Hi Beau6183,

Thanks a lot for your info. How about if I wanna display all the tables name available in my database into the listbox ? Thank you !

regards,
Larva

What kind of database are you using? Are you using SQL connectivity or ADO? If you are using ADO, it does not support table cataloging. The only way to do this is to create another table that acts as a list of the existing tables -- you'll have to input this data and keep it updated. However, SQL does support cataloging:

'---|| SQL Table Catalog ||---

'--- Create an instance of the SQL Server Connection ---
Dim OServer, oSQLdb as Object
Set OServer = CreateObject("sqlole.sqlserver")
OServer.Connect "MyServerName", "MyUserID", "MyPassword"

'--- Connect to the specific database on the SQL Server ---
Set oSQLdb = oServer.Databases(MyDatabaseName)

'--- Loop through each table name and assign the value to a listbox (list1) ---
Dim objTable, i
i = 0
For Each objTable in oSQLdb.Tables
     List1.AddItem objTable.Name, i
     i = i + 1
Next
 
Hi Beau6183,

I m trying to use Java and VB6.0 ADO to connect to my Oracle8i DB. In the last message u wrote :

Dim OServer
Set OServer = CreateObject("sqlole.sqlserver")
OServer.Connect "MyServerName", "MyUserID", "MyPassword"

'--- Loop through each table name and assign the value to a listbox (list1) ---
Dim objTable, i
i = 0
For Each objTable in OServer.Tables
List1.AddItem objTable.Name, i
i = i + 1
Next

What should the OServer 'Dim' As ? Like ADODB.Connection or something else ? If I don't Dim as something, I got an error message when compile.
The "MyServerName" is the DB Service name or the Server name ? Thanks !


regards,
Larva

 
Originally posted by: larva
Hi Beau6183,

I m trying to use Java and VB6.0 ADO to connect to my Oracle8i DB. In the last message u wrote :

Dim OServer
Set OServer = CreateObject("sqlole.sqlserver")
OServer.Connect "MyServerName", "MyUserID", "MyPassword"

'--- Loop through each table name and assign the value to a listbox (list1) ---
Dim objTable, i
i = 0
For Each objTable in OServer.Tables
List1.AddItem objTable.Name, i
i = i + 1
Next

What should the OServer 'Dim' As ? Like ADODB.Connection or something else ? If I don't Dim as something, I got an error message when compile.
The "MyServerName" is the DB Service name or the Server name ? Thanks !


regards,
Larva

It'll work if you just dim at as an object, but I suppose you could do it as a SQLOLE.SQLServer.
MyServerName should be the Server name. I left out a line, check the original post.
 
Originally posted by: larva
Hi Beau6183,

I m trying to use Java and VB6.0 ADO to connect to my Oracle8i DB. In the last message u wrote :

Dim OServer
Set OServer = CreateObject("sqlole.sqlserver")
OServer.Connect "MyServerName", "MyUserID", "MyPassword"

'--- Loop through each table name and assign the value to a listbox (list1) ---
Dim objTable, i
i = 0
For Each objTable in OServer.Tables
List1.AddItem objTable.Name, i
i = i + 1
Next

What should the OServer 'Dim' As ? Like ADODB.Connection or something else ? If I don't Dim as something, I got an error message when compile.
The "MyServerName" is the DB Service name or the Server name ? Thanks !


regards,
Larva

there is a system table called ALL_TAB_COLUMNS and another one called ALL_TABLES
in oracle 8i

you can just select the info you need from these tables

🙂

hope this helps


 
select * from all_tables

select * from all_tabs_columns where table_name ="yourtable"

and just check for what you need...
 
Back
Top