将表格列表数据转换为C#中的Rowa

时间:2013-02-04 23:23:29

标签: c#

我正在查询数据库以获取表格数据

ID   NAME
1     ABC
2     XYZ
3     IJK
4     LMN
5     OPQ
6     RSS
7     NTN
8     UPS
9     DHL
10    XXX   

I want this to convert it into following format to display in Grid

1  ABC    2 XYZ     3 IJK
4  LMN    5 OPQ     6 RSS
7  NTN    8 UPS     9 DHL
10 XXX


I want to Convert it into a List of Following Object

Class NewData
{
  Int Id1
  string Name1
  int id2
  string Name2
  int id3
  string Name3

}

1 个答案:

答案 0 :(得分:0)

或者你可以用

之类的东西来查询它
Select C1.ID,C1.Name, C2.ID,C2.Name, C3.ID,C3.Name 
From MyTAble c1
Left Join MyTable c2 On c2.ID = (C1.ID + 1)
Left Join MyTable c3 On c3.ID = (C1.ID + 2)
Where ((C1.ID -1) % 3) = 0;

注意这是有效的,因为你的ID是连续的。如果不是,就会留下空白。