ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 18th, 2003, 01:54 AM
Agarash Agarash is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: South Africa
Posts: 53 Agarash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 35 sec
Reputation Power: 6
Grab the Database Column Names??

im reading from multiple databases, and one restraint is that i must know the amount of columns and the names of the columns before i can display info from the database.

my question: can i somehow GRAB or READ this information from each database and then just adapt my Display accordingly???

thanks
__________________
"Morgoth i Cried
All Hope is Gone
But i Swear REVENGE
Hear my Oath!!"

Reply With Quote
  #2  
Old July 18th, 2003, 07:52 AM
Silian's Avatar
Silian Silian is offline
Gogga
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 198 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I'm not shure what database you are using. If you're using Microsoft SQL server, you can use the sysobject table to get the table names, syscolumns gives you the columns in the table, and systypes the (I guess this is obvious) types. The following query can be used to get all the tables, columns and types (If you use a count, you should be able to find the number of columns as well).

I don't know if other databases also store their tables, columns etc. in seperate tables. They probably do, so you can search for tables with names that look funny

Code:
select a.name, b.name, c.name from sysobjects a
left join syscolumns b on (b.id = a.id)
left join systypes c on (c.xtype = b.xtype)
where a.xtype = 'u'
order by a.id, b.colorder

Reply With Quote
  #3  
Old July 21st, 2003, 01:13 AM
Agarash Agarash is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: South Africa
Posts: 53 Agarash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 35 sec
Reputation Power: 6
ok, thanks, i know nothing about 'sys'objects.. but ill check it out...thanks alot.

Reply With Quote
  #4  
Old July 21st, 2003, 01:24 AM
Agarash Agarash is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: South Africa
Posts: 53 Agarash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 35 sec
Reputation Power: 6
hmm... im working with ms access.. doe sthe query work with access??

Reply With Quote
  #5  
Old July 21st, 2003, 01:36 AM
roninblade's Avatar
roninblade roninblade is offline
// no comment
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2001
Posts: 1,639 roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level)roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level)roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level)roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level)roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level)roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 45 m
Reputation Power: 33
here's a sample. HTH.
Code:
' objRecordset is the result object of your database query

for each Fields in objRecordset.Fields
  response.write (Fields.Name & " : " & Fields.Value)
next
this will display all your field name and values from any database query you made even in msAccess.

number of fields/columns can be taken from : objRecordset.Fields.Count

Reply With Quote
  #6  
Old July 21st, 2003, 01:57 AM
Agarash Agarash is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: South Africa
Posts: 53 Agarash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 35 sec
Reputation Power: 6
GREAT!!!!! Works like a charm!!! thanks alot man!!! now only the databas ename also.... but that cant be to hard right?

thanks

Reply With Quote
  #7  
Old July 21st, 2003, 02:14 AM
Silian's Avatar
Silian Silian is offline
Gogga
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 198 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
roninblade - This is brilliant. I should have thought of it myself Thanks

Reply With Quote
  #8  
Old July 21st, 2003, 02:27 AM
roninblade's Avatar
roninblade roninblade is offline
// no comment
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2001
Posts: 1,639 roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level)roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level)roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level)roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level)roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level)roninblade User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 45 m
Reputation Power: 33
no problem guys. im only starting out with asp myself.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Grab the Database Column Names??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway