我正在尝试使用来自SQL Server CE数据库的记录进行排列,但是我每次都有不同的结果,尤其是20选择5 = 15504
我在C#内部的C#中循环5,从一个表中读取日期
for(int i=1;i<n;i++)
{
for (acv1=1; acv1 <= n; acv1++)
{
string sql = "SELECT PId,DateOFVisit,RaId,VisitNum from tblPatientVisit";
visit1 = new ArrayList();
if (id > 0)
{
sql += "n where PId= " + id + "AND VisitNum=" + acv1;
}
try
{
SqlCeCommand cm1 = new SqlCeCommand(sql, f.conn);
SqlCeDataAdapter da1 = new SqlCeDataAdapter(cm1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
foreach (DataRow dr in dt1.Rows)
{
visit1.Add(dr["VisitNum"].ToString());
visit1.Add(dr["PId"].ToString());
visit1.Add(p_name);
visit1.Add(dr["DateOfVisit"].ToString());
visit1.Add(description(Convert.ToInt32(dr["RaId"])));
break;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
for(int x=i+1;x<n;x++)
{
// select statement here for x and stored it on array list b
for(int y=x+1;y<n;y++)
{
// select statement here for y and stored it on array list c
for(intz=y+1;z<n;z++)
{
// select statement here for z and stored it on array list d
for(int t=z+1;z<n;z++)
{
// select statement here for t and stored it on array list e
// in order to insert the array lists in order but i got different result than I expected
}
}
}
}
}
我想获得这样的结果
1 2 3 4 5
1 2 3 4 6
1 2 3 4 7
1 2 3 4 8
1 2 3 4 9
1 2 3 4 10
1 2 3 4 11
1 2 3 4 12
1 2 3 4 13
直到
16 17 18 19 20
我从上面的代码中得到的
16 2 4 6 10
编辑:
我在tblACV
上有20个记录,我想阅读此记录并为记录进行排列,然后将它们再次存储到另一个表中
我不确定这是您真正想要的,但这会让数字说您期望:
int n = 20;
for ( int i = 4; i < n; i++) {
for ( int j = 0; j < 4; j ++ ) {
System.out.print(j + 1);
}
System.out.println(i + 1);
}