Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!

What is the best way to obtain a list of user defined tables?
I would like to add them to a combo box in my program.

Here is what I have so far:
C#
SqlCeCommand getTables_comm = new SqlCeCommand("SELECT table_name from user_tables", conn);

getTables_comm.CommandType = CommandType.Text;
getTables_comm.ExecuteNonQuery();

conn is defined as the connection to the database.

The following error is what I'm receiving as a result of running this code:
An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll.

This error is pointing to the ExecuteNonQuery command.

Does anyone have any advice as to what I'm doing wrong and how to resolve this sqlserver error message?
Posted
Updated 21-Jan-13 6:11am
v3

Try:
SQL
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
It returns all table names in the database.
 
Share this answer
 
Specifically include the name of the database (as well as the schema if possible like:
USE [database]
GO
SELECT * FROM sys.tables WHERE [type] = 'U'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900