将列表框链接到数据集表名。 [英] Link listbox to dataset tablenames.
本文介绍了将列表框链接到数据集表名。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的c#应用程序中有一个列表框。我希望它显示数据集的所有表名。
我尝试过:
我尝试使用listBox.Items.Add(mydataSet()。Tables.ToString();但似乎没有工作
I have a listbox in my c# application. I want it to display all the table names of the dataset.
What I have tried:
I tried using the listBox.Items.Add(mydataSet().Tables.ToString(); but seems not to work
推荐答案
DataSet.Tables
的类型为 DataTableCollection [ ^ ]。如果调用ToString()在那,你得到默认的ToString() - 实现,它只给你类型名称。
AsDataTableCollection
未实现IEnumerable<>
(这将允许您调用.Select(table => ta ble.TableName)
就可以了)你唯一的选择是遍历包含的表(使用for循环或foreach循环),将表的名称添加到列出< string>
然后使用.AddRange(..)将该列表中的项目添加到
。ListBox
DataSet.Tables
is of type DataTableCollection[^]. If you call ToString() on that, you get the default ToString()-implementation which just gives you the type name.
AsDataTableCollection
doesn't implementIEnumerable<>
(which would allow you to call.Select(table => table.TableName)
on it) your only option is to loop over the contained tables (either with a for-loop or a foreach-loop), add the names of the tables to aList<string>
and then add the items in that list to yourListBox
with.AddRange(..)
.
您好,请更改您的代码,
Hi, change your code like this,
for(int i = 0; i < mydataSet.Tables.Count; i++)
{
listBox.Items.Add(mydataSet.Tables[i].TableName);
}
嗨朋友,
使用此查询。这将返回数据库中存在的表格列表。
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
将此列表绑定到您的下拉菜单。
尝试这个希望这将有所帮助,
谢谢..
Hi Friend,
use this query. this will return you list of tables present in your database .
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
bind this list to your drop down.
try this hope this will help,
thanks..
这篇关于将列表框链接到数据集表名。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文