Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
Imports CrystalDecisions.CrystalReports.Engine
Imports MySql.Data.MySqlClient
Public Class referralview

    Private Sub referralview_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strsql As String
        strsql = "select *  from report4 where cdate = " & List.DataGridView1.SelectedRows(0).Cells(0).Value.ToString & " order by cdate desc"
        Dim cmd As New MySqlCommand
        Dim adpter As New MySqlDataAdapter
        Dim dt As New DataTable

        With cmd
            .CommandText = strsql
            .Connection = List.connect
        End With

        With adpter
            .SelectCommand = cmd
            .Fill(dt)

        End With
        Dim crystal As New CrystalReport4
        crystal.SetDataSource(dt)
        CrystalReportViewer3.ReportSource = crystal
        CrystalReportViewer3.Refresh()
    End Sub
End Class
Posted
Updated 2-Mar-15 8:52am
v3
Comments
ZurdoDev 2-Mar-15 12:45pm    
Do yo understand what the error is telling you?

What line of code causes it?
sudevsu 2-Mar-15 13:25pm    
Is there any value filled in your Datatable dt?

1 solution

Let's see: List.DataGridView1.SelectedRows needs to have at least one row to allow you to get any row at index 0. On next step, likewise, if the row at index 0 does exist, List.DataGridView1.SelectedRows(0).Cells needs to have at least one cell to allow you to get any cell at index 0. Execute it under the debugger and inspect those objects. Then modify your code to check up that the objects indexed like that exist before accessing the collection elements by indices.

—SA
 
Share this answer
 
Comments
Maciej Los 2-Mar-15 14:54pm    
Sounds reasonable ;)
Sergey Alexandrovich Kryukov 2-Mar-15 14:57pm    
Sure it is reasonable... :-)
Thank you, Maciej.
—SA
Maciej Los 2-Mar-15 15:20pm    
I knew it that you like it ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900