-6

SQL Server CE データベースのレコードを使用して順列を実行しようとしていますが、毎回異なる結果が得られ、特に 20 の場合は 5 = 15504 を選択します

1 つのテーブルから日付を読み取る C# の for ループを相互に 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 

編集 :

に 20 のレコードがあり、tblACVこのレコードを読み取り、レコードの順列を作成して、それらを別のテーブルに再度保存したい

4

1 に答える 1

0

I am not certain that this is what you are really looking for but this would give the numbers say you are expecting:

    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);
    }
于 2012-11-09T16:16:37.947 に答える