Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server CE / October 2006

Tip: Looking for answers? Try searching our database.

List of tables (C#)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
master - 21 Sep 2006 16:23 GMT
Hi,

I am new to SQL CE.

How to get the list of tables in a database? In C#.

Thanks for your help...

DW
João Paulo Figueira - 21 Sep 2006 22:16 GMT
Hello master,

Use this:

SELECT * FROM INFORMATION_SCHEMA.TABLES

Regards,
João Paulo Figueira
Device Application Development MVP

> Hi,
>
[quoted text clipped - 5 lines]
>
> DW
master - 09 Oct 2006 08:45 GMT
> Use this:
> SELECT * FROM INFORMATION_SCHEMA.TABLES

Thanks.
Steve B. - 04 Oct 2006 13:06 GMT
Here is code that you can use :

/// <summary>
/// Return the list of user tables
/// </summary>
/// <param name="connection"></param>
/// <returns></returns>
private static string[] EnumTables(
SqlCeConnection connection
)
{
if (connection == null)
throw new ArgumentNullException("connection");
return EnumTables(connection, TableTypeFilter.User);
}
/// <summary>
/// Return the filtered list of tables
/// </summary>
/// <param name="connection"></param>
/// <param name="filter">Specify type of table to list</param>
/// <returns></returns>
private static string[] EnumTables(
SqlCeConnection connection,
TableTypeFilter filter
)
{
if (connection == null)
throw new ArgumentNullException("connection");
SqlCeCommand cmd;
IDataReader reader;
ArrayList result = new ArrayList();
cmd = connection.CreateCommand();
// Configure command
switch(filter)
{
case TableTypeFilter.None:
return null;
case TableTypeFilter.Both:
cmd.CommandText = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES";
break;
case TableTypeFilter.System:
cmd.CommandText = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'System'";
break;
case TableTypeFilter.User:
cmd.CommandText = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'TABLE'";
break;
}
bool wasOpened = (connection.State == ConnectionState.Open);
if (!wasOpened) connection.Open();
// Create the datareader
reader = cmd.ExecuteReader();
while(reader.Read())
result.Add(reader.GetString(0));
reader.Close();
reader.Dispose();
if (!wasOpened) connection.Close();
return (string[])result.ToArray(typeof(string));
}
/// <summary>
/// Enumerate table types
/// </summary>
[Flags]
internal enum TableTypeFilter
{
/// <summary>
/// No table is returned
/// </summary>
None = 0,
/// <summary>
/// Only user tables are retrieved
/// </summary>
User = 1,
/// <summary>
/// Only system tables are retrieved
/// </summary>
System = 2,
/// <summary>
/// Both user and system tables are retrieved
/// </summary>
Both = 3
}

> Hi,
>
[quoted text clipped - 5 lines]
>
> DW
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.