【发布时间】:2012-11-09 15:43:56
【问题描述】:
我正在尝试对 SQL Server CE 数据库中的记录进行排列,但每次都有不同的结果,尤其是 20 选择 5 = 15504
我在 C# 中创建了 5 个 for 循环,它们从一个表中读取日期
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 条记录,我想读取这条记录并对记录进行排列并将它们再次存储到另一个表中
【问题讨论】:
-
我听不懂你在做什么。请清理您的格式,不要排除“此处选择语句”代码。你的最终目标是什么?不要只告诉我们你在做什么——还要告诉我们你想要做什么。可能有更好的方法。
-
我做了一些编辑以使其清晰
-
这并没有更清楚 - 大括号的负载有什么意义!
-
将您的所有代码放在一个代码块中。按 ctrl+K 对其进行格式化并检查预览以确保它看起来已格式化 - 如果没有,请再次按 ctrl+K。然后,在单独的段落中告诉我们代码块的作用,而不是在每一行代码之间。并且不要排除您显示的“选择...”语句。我仍然不知道你想从你的循环中实现什么。
-
来自另一种方法 n= 10 或 20 取决于患者就诊次数
标签: c# sql sql-server-ce