1
我有組SQL語句通過和參數:與參數和OleDbCommand的工作。在分組時,Crystal Reports
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','')))";
沒有任何問題。
有人可以幫我嗎?
是的,問題出在那一部分。當我把正確的價值,如上所示,它工作正常。但是當我想使用用戶選擇的值時,在按下按鈕之前使用表單,出現錯誤。那麼,什麼時候用?參數。我試過了 '?'以及,但沒有改變。這裏是我如何填寫?:if(radioButton5.Checked == true) { command.Parameters.AddWithValue(「@ gbr1」,「1001」); command.Parameters.AddWithValue(「@ gbr2」,「1080」); button1.Enabled = true; textBox1.Text =「」; } ...... – user963833
當你使用'Parameters'時,你必須將它們分配給合適的字段而不是'?' – NaveenBhat
是的,我知道,我按照適當的順序使用它們,而我使用6參數。當我使用它,因爲你建議我command.Parameters.Add(「1001」);我得到這個錯誤:OleDbParameterCollection只接受非空的OleDbParameter類型對象,而不是String對象。 – user963833