Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse ADO to display SQL Server tables and records in a TreeView control
KeywordsADO, SQL Server, database
CategoriesDatabase
 
This example uses the ADODB.Connection object to execute SQL statements that fetch information describing the database structure. The following table shows the SQL statements the program uses to learn about different parts of the database.

InformationSQL Statement
Databases on Server
SELECT Name
FROM sysdatabases
WHERE Name NOT IN ('Master','Tempdb','Model','msdb')
Tables in Databases
SELECT table_name
FROM INFORMATION_SCHEMA.TABLES
WHERE table_type = 'base table'
ORDER BY table_name
FROM sysdatabases
WHERE Name NOT IN ('Master','Tempdb','Model','msdb')
Columns in a Table
SELECT top 1 *
FROM <table name>
Records in a Table
SELECT top <number>
FROM <table name>
WHERE <where condition>

Thanks to Roberts Bill.

Check out my book Visual Basic.NET Database Programming for lots more information on exploring and manipulating SQL Server, MSDE, Access, and other databases using Visual Basic .NET.

 
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated