|
-
Jun 11th, 2000, 02:52 PM
#1
Thread Starter
Lively Member
I'm populating a treeview using table/field names.
The table names I've done using sysobjects but what I need is for VB to pass the table name to SQL and to return all the field names for that table.
-
Jun 11th, 2000, 03:22 PM
#2
Fanatic Member
Hi Frank
If you are using ADO You can use this piece of code
Code:
strSQL = "SELECT * FROM " & yourtable
myrecordset.Open strSQl,Myconnection
Iflag = myrecordset.fields.count - 1
For i = 0 to Iflag
myvariable = myrecordset.fields(i).name
' Enter code here to put it into your list view
Next
Hope This Helps
Ian
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jun 11th, 2000, 04:43 PM
#3
Thread Starter
Lively Member
Ian,
Thought of that. Problem is that that will bring back all the data as well. I've got some tables in excess of 100K records.
I was hoping for some kind of schema object somewhere/anywhere.
-
Jun 11th, 2000, 10:17 PM
#4
Guru
what database are you using, frank?
you could also use
Select * from MyTable where MyField = -1
if your MyField field is an autonumber/pri key (or other indexed field), you'll just return the table structure
HTH
Tom
-
Jun 12th, 2000, 03:15 PM
#5
Thread Starter
Lively Member
Clunietp,
I'm using SQL 7
Where you mention MyField do you mean
Dim myField as Field
"Select * from " & strMyTable & " where " & MyField & "= -1"
-
Jun 12th, 2000, 09:35 PM
#6
Lively Member
OK, if you're using treeview control think of filling each branch on node.expand event. I mean that when you initialize the tree you fill only the first-level nodes. When you expand a specific node you fill it's child nodes and so on. In this way you don't have to bring all the records at once and the things work much faster
-
Jun 12th, 2000, 09:39 PM
#7
Thread Starter
Lively Member
Just found out that THE way to do it is to call sp_columns.
ie
exec sp_columns 'tablename'
in Query Analyzer grid view
 VB6 Enterprise sp5, SQL Server2000 
-
Jun 13th, 2000, 12:02 AM
#8
Guru
I meant that MyField would be your primary key field....but you have figured out another way so forget it, I guess...
Tom
-
Jun 14th, 2000, 01:34 AM
#9
Thread Starter
Lively Member
Thanks for your reply Clunietp but the problem was that I wouldn't know the names of either the tables or the fields in advance!
 VB6 Enterprise sp5, SQL Server2000 
-
Jun 14th, 2000, 10:50 AM
#10
Guru
gotcha
you can also use ADOX to retrieve database info as well if you don't want to tie yourself to SQL Server (but I doubt that the other drivers support this functionality, except maybe the Jet 4.0 provider....)
-
Jun 15th, 2000, 12:54 AM
#11
Thread Starter
Lively Member
Yeah!
Only found out about a way using ADO after the event.
Cheers!
 VB6 Enterprise sp5, SQL Server2000 
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
|