有没有人知道为什么我在datagridview中抛出零,而我的整个查询代码都是正确的..这是我下面的代码..
boAPI4.Login login = new boAPI4.Login();
string cS = login.GetConnectionString();
DataAccess dA = new DataAccess(cS);
int userID = dA.getLpeID(login.GetBoUserNr());
PRAESENZZEIT q = new PRAESENZZEIT();
q.ZPZ_LPE_ID = userID;
if (db.State == ConnectionState.Closed)
db.Open();
string query = "SELECT per.LPE_Nr, zei.ZPZ_LPE_ID, zei.ZPZ_Datum, SUM (zei.ZPZ_Std100) AS Stunden" +
" FROM DB.dbo.Z_PRAESENZZEIT zei INNER JOIN DB.dbo.A_PERSONAL per ON zei.ZPZ_LPE_ID = per.LPE_ID" +
$" WHERE zei.ZPZ_Datum BETWEEN '{dtFromDate.Value}' AND '{dtToDate.Value}' AND zei.ZPZ_LPE_ID='{userID.ToString()}' GROUP BY per.LPE_Nr, zei.ZPZ_LPE_ID, zei.ZPZ_Datum ORDER BY zei.ZPZ_Datum, per.LPE_Nr;";
pRAESENZZEITBindingSource.DataSource = db.Query<PRAESENZZEIT>(query, commandType: CommandType.Text);
,这是应该在datagridview
中编写的查询 SELECT per.LPE_Nr, zei.ZPZ_LPE_ID, zei.ZPZ_Datum, SUM (zei.ZPZ_Std100) AS Stunden FROM DB.dbo.Z_PRAESENZZEIT zei INNER JOIN DB.dbo.A_PERSONAL per ON zei.ZPZ_LPE_ID = per.LPE_ID WHERE zei.ZPZ_Datum BETWEEN '16.12.2014 13:56:00' AND '18.12.2017 15:15:17'AND zei.ZPZ_LPE_ID='196' GROUP BY per.LPE_Nr, zei.ZPZ_LPE_ID, zei.ZPZ_Datum ORDER BY zei.ZPZ_Datum, per.LPE_Nr;
PRAESENZZEIT类的定义
public class PRAESENZZEIT
{
public int LPE_Nr { get; set; }
public DateTime ZPZ_Datum { get; set; }
public double ZPZ_Std100 { get; set; }
public int ZPZ_LPE_ID { get; set; }
public DateTime ZPZ_Von { get; set; }
public DateTime ZPZ_Bis { get; set; }
public DateTime ZPZ_Std { get; set; }
public int ZPZ_ID { get; set; }
public int ZPZ_Jahr { get; set; }
public int ZPZ_Monat { get; set; }
public int ZPZ_Tag { get; set; }
public DateTime ZPZ_ERFDAT { get; set; }
public string ZPZ_ERFUSER { get; set; }
public DateTime ZPZ_MUTDAT { get; set; }
public string ZPZ_MUTUSER { get; set; }
}
答案 0 :(得分:1)
在不了解您的系统的情况下,我只能做出有根据的猜测,但您可能希望从中更改您的查询:
SUM (zei.ZPZ_Std100) AS Stunden
到此:
SUM (zei.ZPZ_Std100) AS ZPZ_Std100
这是因为类PRAESENZZEIT
有一个名为ZPZ_Std100
的属性,但没有一个名为&#34; Stunden&#34;。
我希望db.Query<PRAESENZZEIT>
会进行反射,将结果集映射到属性名称,因此您需要使用列名来匹配您的属性名称。