gpt4 book ai didi

c# - DataGridview查询0的结果

转载 作者:行者123 更新时间:2023-11-29 10:28:27 25 4
gpt4 key购买 nike

有谁知道为什么我在 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;

[This is my result in base and datagridview]

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; }
}

最佳答案

在不了解您的系统的情况下,我只能做出有根据的猜测,但您可能想更改您的查询:

SUM (zei.ZPZ_Std100) AS Stunden

对此:

SUM (zei.ZPZ_Std100) AS ZPZ_Std100

这是因为类 PRAESENZZEIT有一个名为 ZPZ_Std100 的属性但没有一个名叫“Stunden”的人。

我预计db.Query<PRAESENZZEIT>将进行反射以将结果集映射到属性名称,因此您需要列名称与属性名称相匹配。

关于c# - DataGridview查询0的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47871217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com