0

hi I am new in programming and I hope all with respect to help me I create a form with vb.net EX: "main Branches " and I want to print current data record so I create another form and put RDCL report in it and it is run well but showing all record. i want the report show only the current record

note:-

  • if i remove where condition the report show all data and if i use where condition it does not show any record

    ' the form which contain the record ' Private Sub BTN_PRINT_Click(sender As Object, e As EventArgs) Handles BTN_PRINT.Click

              Dim f As New Form1
              f.ShowDialog()
    
    
    
          End Sub
    
      ''the form which contain rdcl report ''
    
      Private Sub ReportViewer1_Load(sender As Object, e As EventArgs) Handles ReportViewer1.Load
    
              Dim codee As String = FRM_BR.TXT_code.Text
              Dim CON As New SqlConnection("Data Source=MOHAMEDTHRWAT20\SQLEXPRESS;Initial Catalog=data_egy;User ID=sa")
              Dim COM As New SqlCommand("SELECT * FROM [dbo].[tb_br] where code ='" & codee & "' ", CON)
              Dim SD As New SqlDataAdapter(COM)
              Dim DTa As New DataTable
    
              SD.Fill(DTa)
    
              With Me.ReportViewer1.LocalReport
                  .DataSources.Clear()
                  .ReportPath = "C:\Users\mothr\onedrive\المستندات\visual studio 2012\Projects\WindowsApplication1\WindowsApplication1\PL\PL_ACC\Report1.rdlc"
                  .DataSources.Add(New ReportDataSource("DataSet1", DTa))
    
              End With
              Me.ReportViewer1.RefreshReport()
          End Sub
    
  • as you filter already for the code, it shouldn't show all data, but you can see when you haltafter the fill teh content of DTa. Please see also prepared statements https://stackoverflow.com/a/7351190/5193536 you code is vulnerable – nbk Jul 20 '22 at 07:29
  • You don't need a report to print some data. You can just use a PrintDocument, handle the PrintPage event and call Print. – John Jul 20 '22 at 08:20
  • _if i remove where condition the report show all data and if i use where condition it does not show any record_ To me, this would suggest that the value of codee is not actually contained in the tb_br table. Being a string you will need to make sure character casing matches. Maybe using something like Upper() of both sides of the where condition might be enough – Hursey Jul 20 '22 at 20:30

0 Answers0