dejanm
dejanm

Reputation: 133

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 ..

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

  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]

definition of class 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; }
}

Upvotes: 0

Views: 42

Answers (1)

Crowcoder
Crowcoder

Reputation: 11514

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".

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.

Upvotes: 1

Related Questions