Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Print Structure
Message
From
25/02/2008 06:05:43
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Databases
Miscellaneous
Thread ID:
01295987
Message ID:
01296000
Views:
24
>Hi.
>Is there a way or utility to print the structure of a SqlExpress database, i.e Tbale names, Field Names etc.
>Regards,
>Gerard

You can use GetSchema method of DbConnection. Here is a sample for a subset:
using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

class SQLDatabaseDiscovery
{
 static void Main()
 {
   string strCon =
      @"server=.\sqlexpress;Database=AdventureWorks;Trusted_Connection=yes";
   SqlConnection con = new SqlConnection(strCon);
   con.Open();
   // Available schemas
   //DataTable schemas = con.GetSchema(); 

   DataTable tables  = con.GetSchema("Tables");
   DataTable views   = con.GetSchema("Views");
   DataTable columns = con.GetSchema("Columns");

   con.Close();

   foreach (DataRow row in tables.Rows)
   {
      Console.WriteLine(row["table_name"]);
   }
   Console.WriteLine("Views in catalog:");
   foreach (DataRow row in views.Rows)
   {
      Console.WriteLine(row["table_name"]);
   }
   Console.WriteLine("Column info in catalog:");
   foreach (DataRow row in columns.Rows)
   {
      Console.WriteLine("{0}.{1}",row["table_name"],row["column_name"]);
   }
 }
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform