Click here to Skip to main content
15,911,848 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
Hello everyone

How can i get all the table names of database and display these table names using combo box. Or store the table names in an array . I am using sqlexpress and c#
Posted

SELECT * FROM Google WHERE (question like 'all tables') AND (database ='SQL Server Express')


[EDIT]

Answering a follow-up question:

Look at your own solution using SqlDataReader. Instead of adding items to a combo box or list box, add the first in some list such as System.Generic.Collection.List<string>. When the list is filled with data, you can turn it into array using its method ToArray.



—SA
 
Share this answer
 
v4
Comments
Mehdi Gholam 16-Oct-11 0:30am    
Hehe!
manu g m 16-Oct-11 0:32am    
How can i store this in an array please help.
Sergey Alexandrovich Kryukov 16-Oct-11 1:41am    
Most direct way: use DataReader, see http://msdn.microsoft.com/en-us/library/haa3afyz%28v=VS.100%29.aspx. All such methods depends on provider -- types are different, but very similar, nearly identical in use.
--SA
Sergey Alexandrovich Kryukov 16-Oct-11 1:54am    
OK, I updated my solution. Please see after [EDIT].
--SA
Mehdi Gholam 16-Oct-11 1:41am    
I don't know whether to laugh or cry, your solution was accepted!!!
Use the following query when you have connected to you database server
SQL
select * from information_schema.tables
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Oct-11 1:49am    
Correct, my 5, but OP asked about filling an array with this data. I added answer to this question to my solution, this time seriously. Please see.
--SA
C#
SqlConnection con1 = new SqlConnection(connection);
            con1.Open();
            SqlCommand cmd1 = new SqlCommand("select name from dbo.sysobjects where xtype='U' ", con1);
            cmd1.ExecuteNonQuery();
            SqlDataReader dr = cmd1.ExecuteReader();
            while (dr.Read())
                comboBox1.Items.Add(dr[0].ToString());
 
Share this answer
 
v3

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