检索数据库的所有表名 [英] Retrieve all table names of a database
本文介绍了检索数据库的所有表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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#
推荐答案
SELECT * FROM Google WHERE (question like ''all tables'') AND (database =''SQL Server Express'')
回答后续问题:
使用SqlDataReader
查看您自己的解决方案.而不是将项目添加到组合框或列表框,而是在某些列表(例如System.Generic.Collection.List<string>
)中添加第一个.当列表中充满数据时,可以使用其方法ToArray
将其转换为数组.
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
.
连接到数据库服务器后使用以下查询
Use the following query when you have connected to you database server
select * from information_schema.tables
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());
这篇关于检索数据库的所有表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文