Nel

Nel

  • NA
  • 716
  • 1.1m

The queries return different results when run as queries in ACCESS and run as command strings for filling the dataset in C# application

Apr 30 2012 3:42 AM
Hi,

I use MS Access database as a database for my C# windows application. I want to get one row for every date as a result from my queries, instead of several. In my C# application I made these command strings with which I fill the dataset tables:

comstring1=
"SELECT MAGACIN.GBR, MAGACIN.DATA, NOVI.AB, Sum(IIf([sifra]='0992201',[kol],Null)) AS Addblue,Sum(IIf([sifra]='0999001',[kol],Null)) AS Antifriz, Sum(IIf([sifra]='0991000',[kol],Null)) AS Gorivo, Sum(IIf([sifra]='0993050',[kol],Null)) AS Motmaslo, Sum(IIf([sifra]='0992201',[kol],Null))/Sum(IIf([sifra]='0991000',[kol],Null))*100 AS Addbluegorivo  FROM MAGACIN INNER JOIN NOVI ON MAGACIN.GBR = NOVI.GBR GROUP BY MAGACIN.GBR, MAGACIN.DATA, NOVI.AB HAVING (((MAGACIN.GBR)=[@gbr1]) AND ((NOVI.AB)=[@ab1] or (NOVI.AB)=[@ab2]) AND ((MAGACIN.DATA)>=[data1] And (MAGACIN.DATA)<=[data2])) ORDER BY MAGACIN.DATA";

the resul for the date>=10.10.20111 and date<=13.10.2011 is


































































GBRDATAABAddblueAntifrizGorivoMotmasloAddbluegorivo
100110.10.2011GP

115

100111.10.2011GP

40

100112.10.2011GP12
110
10,9090909090909
100113.10.2011GP12
125
9,6




comstring2 =
"SELECT NALOG1.GBRV, NALOG1.DATA, Min(IIf(([NALOG1].[POCKM]>0),[NALOG1.POCKM],Null)) AS pockm, Max([NALOG1.KRAJKM]) AS krajkm, Max([NALOG1.KRAJKM])-Min(IIf(([NALOG1].[POCKM]>0),[NALOG1.POCKM],Null)) AS RAZLIKA, Max(NOVI.DATAP) AS Poslprov, Max(NOVI.KMP1) AS KMP, Max(NOVI.DATAS) AS Poslserv, Max(NOVI.KMS1) AS KMS, Sum(NALOG1.km) AS SUMKM, IIf(Sum(NALOG1.km)>=(([NOVI].[KMS1]+[NOVI].[KMS2])-1000),'ZA SERVIS',(IIf(Sum(NALOG1.KM)>=(([NOVI].[KMP1]+[NOVI].[KMP2])-1000),'PROVERKA',' '))) AS Zabeleska FROM NALOG1 INNER JOIN NOVI ON NALOG1.GBRV = NOVI.GBR GROUP BY NALOG1.GBRV, NALOG1.DATA, NOVI.KMP1, NOVI.KMP2, NOVI.KMS1, NOVI.KMS2, NOVI.AB HAVING (((NALOG1.GBRV)=[@gbr1])and ((NOVI.AB)=[@ab1] or (NOVI.AB)=[@ab2]) AND ((NALOG1.DATA)>=[@data1] And (NALOG1.DATA)<=[@data2]))";

the result from the second query is












































































GBRVDATApockmkrajkmRazlikaMaxOfDATAPMaxOfDATASsumkmMaxOfKMP1MaxOfKMS1
100110.10.20114358043867287
27.09.20112874140041400
100111.10.20114386743967100
27.09.20111004140041400
100112.10.20114396744254287
27.09.20112874140041400
100113.10.20114425444541287
27.09.20112874140041400



in the C# windows application I have:
......
command1.CommandText = comstring1;
command2.CommandText = comstring2;
......

oleDBDataAdapter1.SelectCommand = command1;
 oleDBDataAdapter1.Fill(dataSet2, "baraniotselect")
oleDBDataAdapter1.SelectCommand = command2;
oleDBDataAdapter1.Fill(dataSet2, "PocKrajRazl1");


When I run the strings separatelly as queries in Access, I get what I want (for each query), correct result, i.e. one row for every date, but when I use the strings for filling two tables in the dataset, I get several rows for one date, which is not what I am aiming at. I.e. I get several rows for one date with different values for addblue, antifriz, Motmaslo, Addbluegor, gorivo and I want to get for every date of the range a single rows with values for the fields in one row. In other words, I want just to merge both tables which I get as a result from the queries above. 

Could anybody help me please?
Thanks in advance