在数据集上按表名升序的表排序 [英] Order by tables with table name ascending on Dataset
问题描述
嗨其他程序员,
我有一个数据集,其表名如
aa002500T0,hb004400T0,ba000300T0,ba000100T0,...
是否有可能在前端更改下面的升序订单
aa002500T0,ba000100T0,ba000300T0,hb004400T0,...
感谢和问候
george
根据您对其他评论和解决方案的回答,我认为这可能做你需要的......
我的样本数据:
DataSet ds = new DataSet();
ds.Tables.Add( aTable);
ds.Tables.Add( cTable);
ds.Tables.Add( bTable);
我使用CopyTo
将数据集中的表格转换为数组 - 我可以然后使用Linq
DataTable [] dta = new DataTable [ds.Tables.Count];
ds.Tables.CopyTo(dta, 0 );这是实际排序
foreach (DataTable t in dta.OrderBy(c = > c.TableName))
Console.WriteLine(t.TableName);给我输出
aTable
bTable
cTable按预期
编辑 - 忘记提及以确保您已包含使用System.Linq;
Linq将简化这些东西,使用linq你可以获得类似sql的许多功能
希望它帮助你。
你可以在linq中使用orderby
查找下面的示例
http:/ /msdn.microsoft.com/en-us/library/vstudio/bb534966%28v=vs.100%29.aspx [ ^ ]
问候,
Santosh
你可以使用以下查询:
select * from sys .tables
希望它会有所帮助。
问候,
Santosh
Hi fellow programmers,
I have a dataset having table names like
aa002500T0,hb004400T0,ba000300T0,ba000100T0,...
is it possible to change there order in ascending like below in front end
aa002500T0,ba000100T0,ba000300T0,hb004400T0,...
thanks & regards
george
Based on your responses to the other comments and solutions I think this might do what you need ...
My "sample data":
DataSet ds = new DataSet(); ds.Tables.Add("aTable"); ds.Tables.Add("cTable"); ds.Tables.Add("bTable");
I useCopyTo
to get the tables within the dataset into an array - on which I can then use Linq
DataTable[] dta = new DataTable[ds.Tables.Count]; ds.Tables.CopyTo(dta, 0);Here's the actual sort
foreach (DataTable t in dta.OrderBy(c => c.TableName)) Console.WriteLine(t.TableName);which gives me the output
aTable bTable cTableas expected
Edit - Forgot to mention to ensure you have includedusing System.Linq;
Linq will simplify the stuff, using linq you can get many functionalities similar to sql
hope it helps you.
You can use orderby in linq
Find the sample below
http://msdn.microsoft.com/en-us/library/vstudio/bb534966%28v=vs.100%29.aspx[^]
Regards,
Santosh
you can use below query:
select * from sys.tables
hope it will help.
Regards,
Santosh
这篇关于在数据集上按表名升序的表排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!