[英]DataGridview result of query 0
does anyone know why I throws out zero as a result in datagridview, while my entire query code is correct .. This is my code below .. 有谁知道为什么我会在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);
and this is the same query that should be written in datagridview 这是应该在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;
definition of class PRAESENZZEIT 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; }
}
Without knowing your system I can only make an educated guess, but you probably want to change your query from this: 在不知道您的系统的情况下,我只能做出有根据的猜测,但是您可能希望从此更改查询:
SUM (zei.ZPZ_Std100) AS Stunden
to this: 对此:
SUM (zei.ZPZ_Std100) AS ZPZ_Std100
This is because class PRAESENZZEIT
has a property named ZPZ_Std100
but not one named "Stunden". 这是因为类PRAESENZZEIT
具有一个名为ZPZ_Std100
的属性,但没有一个名为“ Stunden”的属性。
I expect db.Query<PRAESENZZEIT>
will do reflection to map the result set to property names so you need your column names to match your property names. 我希望db.Query<PRAESENZZEIT>
会进行反射以将结果集映射到属性名称,因此您需要使用列名称来匹配属性名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.