Click here to Skip to main content
12,355,505 members (72,109 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# SQL Forms VS2012
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 6:03am
Edited 21-Jan-13 6: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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2016
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