我有一个带有group by和参数的sql语句:
string comstring =
"SELECT NOVI.GBR as gbrnov,
NOVI.AB as abnov,
NALOG1.DATA as datanov,
Min(NALOG1.POCKM) AS MinOfPOCKM,
Max(NALOG1.KRAJKM) AS MaxOfKRAJKM,
(Max(NALOG1.KRAJKM)-Min(NALOG1.POCKM)) AS RAZLIKA,
Count(IIf(([MAGACIN.SIFRA]='0991000'),[MAGACIN.KOL],Null)) AS Gorivo,
Avg(IIf(([MAGACIN.SIFRA]='0991000'),[MAGACIN.KOL],Null)/100) AS potrosgor100km,
Sum(IIf(([MAGACIN.SIFRA]='0993050' Or [MAGACIN.SIFRA]='0993051'),[MAGACIN.KOL],Null)) AS Motmaslo,
Sum(IIf(([MAGACIN.SIFRA]='0992201'),[MAGACIN.KOL],Null)) AS Addblue,
([Addblue]/[Gorivo])*100 AS Addbluegor,
Sum(IIf(([MAGACIN.SIFRA]='0999001'),[MAGACIN.KOL],Null)) AS Antifriz,
NOVI.DATAP,
NOVI.DATAS,
IIf(([NOVI].[KM]<=([NOVI].[KMS1]+[NOVI].[KMS2])),'ZA SERVIS',(IIf(([NOVI].[KM]<=([NOVI].[KMP1]+[NOVI].[KMP2])),'PROVERKA',''))) AS Zabeleska
FROM (NALOG1 INNER JOIN NOVI ON NALOG1.GBRV = NOVI.GBR)
INNER JOIN MAGACIN ON NOVI.GBR = MAGACIN.GBR
where (((NOVI.GBR)>=? And (NOVI.GBR)<=?)
AND ( ((NOVI.AB)=?)
OR ((NOVI.AB)=?) )
AND ((NALOG1.DATA)<=? and (NALOG1.DATA)>=?) )
GROUP BY NOVI.GBR,
NOVI.AB,
NALOG1.DATA,
([Addblue]/[Gorivo])*100,
NOVI.DATAP,
NOVI.DATAS,
IIf(([NOVI].[KM]<=([NOVI].[KMS1]+[NOVI].[KMS2])),'ZA SERVIS',(IIf(([NOVI].[KM]<=([NOVI].[KMP1]+[NOVI].[KMP2])),'PROVERKA','')))";
我在
中收到错误No value given for one or more required parameters
oleDBDataAdapter1.Fill(dataSet2,"Tabela");
使用某些值时,例如:
string comstring =
"SELECT NOVI.GBR as gbrnov,
NOVI.AB as abnov,
NALOG1.DATA as datanov,
Min(NALOG1.POCKM) AS MinOfPOCKM,
Max(NALOG1.KRAJKM) AS MaxOfKRAJKM,
(Max(NALOG1.KRAJKM)-Min(NALOG1.POCKM)) AS RAZLIKA,
Count(IIf(([MAGACIN.SIFRA]='0991000'),[MAGACIN.KOL],Null)) AS Gorivo,
Avg(IIf(([MAGACIN.SIFRA]='0991000'),[MAGACIN.KOL],Null)/100) AS potrosgor100km,
Sum(IIf(([MAGACIN.SIFRA]='0993050' Or [MAGACIN.SIFRA]='0993051'),[MAGACIN.KOL],Null)) AS Motmaslo,
Sum(IIf(([MAGACIN.SIFRA]='0992201'),[MAGACIN.KOL],Null)) AS Addblue,
([Addblue]/[Gorivo])*100 AS Addbluegor,
Sum(IIf(([MAGACIN.SIFRA]='0999001'),[MAGACIN.KOL],Null)) AS Antifriz,
NOVI.DATAP,
NOVI.DATAS,
IIf(([NOVI].[KM]<=([NOVI].[KMS1]+[NOVI].[KMS2])),'ZA SERVIS',(IIf(([NOVI].[KM]<=([NOVI].[KMP1]+[NOVI].[KMP2])),'PROVERKA',''))) AS Zabeleska
FROM (NALOG1 INNER JOIN NOVI ON NALOG1.GBRV = NOVI.GBR)
INNER JOIN MAGACIN ON NOVI.GBR = MAGACIN.GBR
where (((NOVI.GBR)>='1001' And (NOVI.GBR)<='1080')
AND ( ((NOVI.AB)='AK')
OR ((NOVI.AB)='AK') )
AND ((NALOG1.DATA)<=#10/31/2011#
and (NALOG1.DATA)>=#10/31/2011#) )
GROUP BY NOVI.GBR,
NOVI.AB,
NALOG1.DATA,
([Addblue]/[Gorivo])*100,
NOVI.DATAP,
NOVI.DATAS,
IIf(([NOVI].[KM]<=([NOVI].[KMS1]+[NOVI].[KMS2])),'ZA SERVIS',(IIf(([NOVI].[KM]<=([NOVI].[KMP1]+[NOVI].[KMP2])),'PROVERKA','')))";
没有任何问题。
是的,有人可以帮帮我吗?答案 0 :(得分:0)
您的查询存在问题:
where (((NOVI.GBR)>=? And (NOVI.GBR)<=?)
AND ( ((NOVI.AB)=?)
OR ((NOVI.AB)=?) )
AND ((NALOG1.DATA)<=? and (NALOG1.DATA)>=?) )
您需要提供正确的值而不是?
,可能您可以'?'
,但我认为它不适用于(NALOG1.DATA)
(通过查看您的其他查询我是猜测一下,它的数据类型是Date
)
编辑评论:
如果您使用参数,则需要按照使用?
的顺序传递它们。您无法在oledbcommand
command.Parameters.AddWithValue("@param1", "1001");
如果您在查询中使用了6 ?
,则需要根据顺序传递6个参数。
OleDbParameter[] oledbParams = new OleDbParameter[6];
//To be added in proper order.
oledbParams[0] = new OleDbParameter("PN1", "1001");
oledbParams[1] = new OleDbParameter("PN2", "1002");
.
.
oledbParams[6] = new OleDbParameter("DateValue", DateTime.Now.Date);
foreach (var p in oledbParams)
{
command.Parameters.Add(p);
}