Hi,

I use the same code 3times for different buttoon , the code shows the SELECT statement in the datagrid view correctly, but it shows the report only for the 2nd code, not for the first or third. I don't know why.


vb Code:
  1. Private Sub cibfnb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cibfnb.Click
  2.        
  3.  
  4.         strcon = "Data Source=xxxx"
  5.  
  6.         icnnn = New SqlConnection()
  7.  
  8.        
  9.         icnnn.ConnectionString = strcon
  10.         Try
  11.             'Open the connection
  12.             icnnn.Open()
  13.         Catch sqlExceptionErr As SqlException
  14.             'Display the error
  15.             MessageBox.Show(sqlExceptionErr.Message, "")
  16.         Catch InvalidOperationExceptionErr As InvalidOperationException
  17.             'Display the error
  18.             MessageBox.Show(InvalidOperationExceptionErr.Message, "")
  19.         End Try
  20.         Me.clientinvoiceReportViewer1.RefreshReport()
  21.         Dim Accesstring As String = ("SELECT     ResID, FirstName As [First Name], LastName As [Last Name], Company, DriverID, paymentamountt As [Payment Amount]  FROM reservation WHERE (FirstName = N'" & cibfn.Text & " ')")
  22.      
  23.         Dim DA As New SqlDataAdapter(Accesstring, icnnn)
  24.         Dim DS As New DataSet
  25.         DA.Fill(DS, "reservation")
  26.         clientinvioiceDataGridViewX1.DataSource = DS.Tables("reservation")
  27.         Dim report As New RptReservation
  28.         report.SetDataSource(DS)
  29.         clientinvoiceReportViewer1.ReportSource = report
  30.  
  31.     End Sub
  32.  
  33.     Private Sub ciblnb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ciblnb.Click
  34.        
  35.         strcon = "Data Source=xxxx"
  36.  
  37.         icnnn = New SqlConnection()
  38.  
  39.    
  40.         icnnn.ConnectionString = strcon
  41.         Try
  42.             'Open the connection
  43.             icnnn.Open()
  44.         Catch sqlExceptionErr As SqlException
  45.             'Display the error
  46.             MessageBox.Show(sqlExceptionErr.Message, "")
  47.         Catch InvalidOperationExceptionErr As InvalidOperationException
  48.             'Display the error
  49.             MessageBox.Show(InvalidOperationExceptionErr.Message, "")
  50.         End Try
  51.         Me.clientinvoiceReportViewer1.RefreshReport()
  52.         Dim Accesstring As String = ("SELECT     ResID, FirstName, LastName, Company, DriverID, paymentamountt  FROM reservation WHERE (LastName = N'" & cibln.Text & " ')")
  53.        
  54.         Dim DA As New SqlDataAdapter(Accesstring, icnnn)
  55.         Dim DS As New DataSet
  56.         DA.Fill(DS, "reservation")
  57.         clientinvioiceDataGridViewX1.DataSource = DS.Tables("reservation")
  58.         Dim report As New RptReservation
  59.         report.SetDataSource(DS)
  60.         clientinvoiceReportViewer1.ReportSource = report
  61.  
  62.  
  63.  
  64.     End Sub
  65.  
  66.     Private Sub cibcnb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cibcnb.Click
  67.        
  68.  
  69.         strcon = "Data Source=xxxx"
  70.  
  71.         icnnn = New SqlConnection()
  72.  
  73.         'Donner à la propriété ConnectionString les paramètres de connexion
  74.         icnnn.ConnectionString = strcon
  75.         Try
  76.             'Open the connection
  77.             icnnn.Open()
  78.         Catch sqlExceptionErr As SqlException
  79.             'Display the error
  80.             MessageBox.Show(sqlExceptionErr.Message, "")
  81.         Catch InvalidOperationExceptionErr As InvalidOperationException
  82.             'Display the error
  83.             MessageBox.Show(InvalidOperationExceptionErr.Message, "")
  84.         End Try
  85.         Me.clientinvoiceReportViewer1.RefreshReport()
  86.         Dim Accesstring As String = ("SELECT     ResID, FirstName As [First Name], LastName As [Last Name], Company, DriverID, paymentamountt As [Payment Amount]  FROM reservation WHERE (Company = N'" & cibcn.Text & " ')")
  87.    
  88.         Dim DA As New SqlDataAdapter(Accesstring, icnnn)
  89.         Dim DS As New DataSet
  90.         DA.Fill(DS, "reservation")
  91.         clientinvioiceDataGridViewX1.DataSource = DS.Tables("reservation")
  92.         Dim report As New RptReservation
  93.         report.SetDataSource(DS)
  94.         clientinvoiceReportViewer1.ReportSource = report
  95.     End Sub