Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:
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 21-Jan-13 7:03am
Edited 21-Jan-13 7:11am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try:
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
It returns all table names in the database.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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'
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.150301.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100