如何将表名称加载到cmbobox [英] how load table names to cmbobox
本文介绍了如何将表名称加载到cmbobox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友.
我需要将所有表名保存到
combobox.But我不知道.我正在使用
vb.net
.please给我代码
hi friends.
I need get all of table names to
combobox.But i have no idea. i am using
vb.net
.please givi me ful code
推荐答案
您的问题有点混乱,我想您要获取数据库表名称.so
如果您使用的是SQL Server
使用此查询
Your question is little confusing,I think you want to fetch database table name.so
If you are using SQL Server
use this query
string str=SELECT name FROM sys.Tables;
SqlCommand cmd = new SqlCommand(str, Db.GetConnection());
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());
}
为什么 ^ ]问题,坚持下去.
**不要向董事会发送垃圾邮件.
谢谢
--RA
Why you are Repost- My Answer[^] the Question , stick on One.
** don''t spam the Board.
Thanks
--RA
尝试一下.
ddlteams是您的组合框
Try this.
ddlteams is your combobox
Dim dt As DataTable
Dim ds As New DataSet()
Dim con As New OdbcConnection(ConnStr)
Dim da As New OdbcDataAdapter("SELECT DISTINCT team FROM phonebook ORDER BY team", con)
con.Open()
da.Fill(ds)
dt = ds.Tables(0)
'To list all tables use "select * from sys.objects where type=’u’"
'*** DropDownlist ***'
With ddlTeams
.DataSource = ds
.DataTextField = "Team"
.DataValueField = "Team"
.DataBind()
End With
con.Close()
问候,
@iamsupergrasya
Regards,
@iamsupergrasya
这篇关于如何将表名称加载到cmbobox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文