Results 1 to 5 of 5

Thread: [RESOLVED] 3 same code

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Resolved [RESOLVED] 3 same code

    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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: 3 same code

    try it this way:

    vb Code:
    1. Private Sub ciblnb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ciblnb.Click
    2.         showReport("SELECT ResID, FirstName, LastName, Company, DriverID, paymentamountt FROM reservation WHERE (LastName = N'" & cibln.Text & " ')")
    3.     End Sub
    4.  
    5.     Private Sub cibcnb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cibcnb.Click
    6.         showReport("SELECT ResID, FirstName, LastName, Company, DriverID, paymentamountt FROM reservation WHERE (Company = N'" & cibcn.Text & " ')")
    7.     End Sub
    8.  
    9.     Private Sub cibfnb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cibfnb.Click
    10.         showReport("SELECT ResID, FirstName, LastName, Company, DriverID, paymentamountt FROM reservation WHERE (FirstName = N'" & cibfn.Text & " ')")
    11.     End Sub
    12.  
    13.     Private Sub showReport(ByVal Accesstring As String)
    14.         strcon = "Data Source=xxxx"
    15.         icnnn = New SqlConnection()
    16.         icnnn.ConnectionString = strcon
    17.         Try
    18.             'Open the connection
    19.             icnnn.Open()
    20.         Catch sqlExceptionErr As SqlException
    21.             'Display the error
    22.             MessageBox.Show(sqlExceptionErr.Message, "")
    23.         Catch InvalidOperationExceptionErr As InvalidOperationException
    24.             'Display the error
    25.             MessageBox.Show(InvalidOperationExceptionErr.Message, "")
    26.         End Try
    27.         Me.clientinvoiceReportViewer1.RefreshReport()
    28.  
    29.         Dim DA As New SqlDataAdapter(Accesstring, icnnn)
    30.         Dim DS As New DataSet
    31.         DA.Fill(DS, "reservation")
    32.         clientinvioiceDataGridViewX1.DataSource = DS.Tables("reservation")
    33.         Dim report As New RptReservation
    34.         report.SetDataSource(DS)
    35.         clientinvoiceReportViewer1.ReportSource = report
    36.     End Sub

  3. #3

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: 3 same code

    Hi,

    As what should I declare showReport ?

    thanks

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: 3 same code

    just use it as it is. theres no need to declare it as anything

  5. #5

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: 3 same code

    Thanks, it's working perfectly.

    Rated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width