Web应用程序和Access 2007查询向导执行的同一查询的结果不同

时间:2015-01-20 09:00:14

标签: c# asp.net ms-access oledb

我正在从我的Web应用程序执行以下查询并访问2007查询向导。我得到了两个不同的结果。

访问查询向导查询:

SELECT
    R.RId,
    R.RNo,
    R.CustId,
    R.WingId,
    R.FloorId,
    R.FlatId,
    FORMAT( R.Rdate, 'DD/MM/YYYY' ) AS Rdate,
    R.Amount,
    C.CustName,
    ( W.Wname + '-' + F.FlatNo ) AS FlatNo,
    Fl.FloorName,
    F.TotalCost,
    (
        SELECT
            SUM( r.Amount )
        FROM
            tblReceipt As r
        WHERE
            r.FlatId = F.FlatId
        GROUP BY
            r.FlatId
     ) AS ReceivedAmt
FROM
    tblFlat AS F
    INNER JOIN (
        tblFloor AS Fl
        INNER JOIN (
            tblWing As W
            INNER JOIN (
                blCust As C
                INNER JOIN tblReceipt As R ON C.CustId = R.CustId
            ) ON W.WingId = R.WingId
        ) ON Fl.FloorId = R.FloorId
    ) ON F.FlatId = R.FlatId 

C#代码:

public DataTable getReceipts(int cmpid)
{
    DataTable dt = new DataTable();
    using (OleDbConnection conn = new OleDbConnection(getConnection()))
    {
        using (OleDbCommand cmd = conn.CreateCommand())
        {
            cmd.CommandType = CommandType.Text;
            cmd.CommandText =  "SELECT " +
    "R.RId," +
    "R.RNo,"+
    "R.CustId,"+
    "R.WingId,"+
    "R.FloorId,"+
    "R.FlatId,"+
    "FORMAT( R.Rdate, 'DD/MM/YYYY' ) AS Rdate,"+
    "R.Amount,"+
    "C.CustName,"+
    "( W.Wname + '-' + F.FlatNo ) AS FlatNo,"+
    "Fl.FloorName,"+
    "F.TotalCost,"+
    "("+
     "   SELECT"+
      "      SUM( r.Amount )"+
       " FROM"+
        "    tblReceipt As r"+
        "WHERE"+
         "   r.FlatId = F.FlatId"+
        "GROUP BY"+
         "   r.FlatId"+
     ") AS ReceivedAmt"+
"FROM"+
"    tblFlat AS F"+
 "   INNER JOIN ("+
  "      tblFloor AS Fl"+
   "     INNER JOIN ("+
    "        tblWing As W"+
     "       INNER JOIN ("+
      "          blCust As C"+
       "         INNER JOIN tblReceipt As R ON C.CustId = R.CustId"+
        "    ) ON W.WingId = R.WingId"+
        ") ON Fl.FloorId = R.FloorId"+
    ") ON F.FlatId = R.FlatId ";

            conn.Open();

            using (OleDbDataReader sdr = cmd.ExecuteReader())
            {
                if (sdr.HasRows)
                    dt.Load(sdr);
            }

        }
    }
    return dt;
}

当我从访问查询向导执行此查询时,我获得" ReceivedAmt"的汇总值。列是正确的,但从Web应用程序运行它不会聚合" ReceivedAmt"我不知道如何得到完全相同的查询不同的结果。如果缺少任何信息,请评论。我卡在这里......请帮忙..

0 个答案:

没有答案