2014-03-05 100 views
1

我必須顯示VB.NET代碼中的數據到水晶報表......我正在做代碼中的所有事情,所以問題在於我必須顯示來自for-each的多個數據循環,這是代碼:報告只顯示最後一條記錄

Private Sub Print_Row(ByVal pp As Boolean) 

     Dim rptDokument As New ReportDocument, brkop As Integer 

     Dim rw_mat As DataRow 

     Dim cn As OracleClient.OracleConnection = New OracleClient.OracleConnection(Gdb_conn) 

     ' Objects used to set the parameters in the report 
     Dim pCollection As New CrystalDecisions.Shared.ParameterValues 

     Dim pTSJ As New CrystalDecisions.Shared.ParameterDiscreteValue 
     Dim pNaziv As New CrystalDecisions.Shared.ParameterDiscreteValue 
     Dim pKolicina As New CrystalDecisions.Shared.ParameterDiscreteValue 
     Dim pTezina As New CrystalDecisions.Shared.ParameterDiscreteValue 

     Try 
      rptDokument.Load(Gpath & "PakLista.rpt") 

      pTSJ.Value = barcode.Text 
      pCollection.Add(pTSJ) 
      rptDokument.DataDefinition.ParameterFields("pTSJ").ApplyCurrentValues(pCollection) 

      cn.Open() 

      Dim myQuery As String = "SELECT S.TSJ,M.NAZ_MAT, S.IBRMAT, S.KOLICINA, S.TEZINA " & _ 
            "FROM TWM_SADRZAJ S, TWM_MATER M, TWM_ATRIBUT A, TWM_PAKIR PAK " & _ 
            "WHERE(S.VLASNIK_MP = M.VLASNIK_MP) " & _ 
            "AND S.IBRMAT = M.IBRMAT " & _ 
            "AND S.ATR_ID = A.ATR_ID (+) " & _ 
            "AND PAK.VLASNIK_MP (+) = S.VLASNIK_MP " & _ 
            "AND PAK.IBRMAT (+) = S.IBRMAT " & _ 
            "AND PAK.PAK (+) = S.PAK " & _ 
            "AND (S.TSJ = '" & barcode.Text & "') " & _ 
            "ORDER BY S.IBRMAT" 

      Dim da As OracleClient.OracleDataAdapter = New OracleClient.OracleDataAdapter(myQuery, cn) 
      Dim ds As New DataSet 

      da.Fill(ds, "TWM_SADRZAJ") 

      For Each rw_mat In ds.Tables("TWM_SADRZAJ").Rows 

       If (rw_mat.Item("NAZ_MAT") Is DBNull.Value) Then 
        pNaziv.Value = "" 
       Else 
        pNaziv.Value = CStr(rw_mat.Item("NAZ_MAT")) 
       End If 

       If (rw_mat.Item("KOLICINA") Is DBNull.Value) Then 
        pKolicina.Value = "" 
       Else 
        pKolicina.Value = CStr(rw_mat.Item("KOLICINA")) 
       End If 

       If (rw_mat.Item("TEZINA") Is DBNull.Value) Then 
        pTezina.Value = "" 
       Else 
        pTezina.Value = CStr(rw_mat.Item("TEZINA")) 
       End If 

       pCollection.Add(pNaziv) 
       rptDokument.DataDefinition.ParameterFields("pNaziv").ApplyCurrentValues(pCollection) 

       pCollection.Add(pKolicina) 
       rptDokument.DataDefinition.ParameterFields("pKolicina").ApplyCurrentValues(pCollection) 

       pCollection.Add(pTezina) 
       rptDokument.DataDefinition.ParameterFields("pTezina").ApplyCurrentValues(pCollection) 

      Next rw_mat 

      If pp Then 
       Dim frm As New frmPrint_preview 
       frm.crvDocument.ReportSource = rptDokument 
       frm.ShowDialog() 
      Else 
       Dim pd As New PrintDialog 
       pd.PrinterSettings = New PrinterSettings 
       If pd.ShowDialog(Me) Then 
        For brkop = 1 To pd.PrinterSettings.Copies 
         rptDokument.PrintOptions.PrinterName = pd.PrinterSettings.PrinterName 
         rptDokument.PrintToPrinter(1, False, 1, 99999) 
        Next brkop 
       End If 
      End If 

     Catch Exp As LoadSaveReportException 
      MsgBox("Incorrect path for loading report.", MsgBoxStyle.Critical, "Load Report Error") 

     Catch Exp As System.Exception 
      MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error") 
     End Try 
    End Sub 

問題是,在本節:

pCollection.Add(pNaziv)   rptDokument.DataDefinition.ParameterFields("pNaziv").ApplyCurrentValues(pCollection) 

pCollection.Add(pKolicina)    rptDokument.DataDefinition.ParameterFields("pKolicina").ApplyCurrentValues(pCollection) 

pCollection.Add(pTezina)    rptDokument.DataDefinition.ParameterFields("pTezina").ApplyCurrentValues(pCollection) 

它必須爲每個循環來收集所有的數據出來的一面,但問題是沒有母校那裏我把這個代碼它只顯示數據行中的最後一條記錄讓我們說5條記錄在水晶報告中......我知道這是蛋糕的平安,但我是繼電器卡在這裏,所以我希望有一點幫助。

回答