Vb.net – How to i display all current rows from datagridview in crystal report using vb.net

crystal-reportsdatagridviewvb.net

I have small issue with my datagridview and crystal report

I am using this code for display my crystal report but my problem is i can display only one row from data grid view

I want to print all rows from datagridview in crystal report

MY CODE

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim SqlQuery As String = "SELECT * FROM BMS_APP WHERE SN = " & BMS_APP.DataGridView1.SelectedRows(0).Cells(0).Value.ToString() & ""
    Dim SqlCommand As New OleDbCommand
    Dim SqlAdepter As New OleDbDataAdapter
    Dim TABLE As New DataTable

    With SqlCommand
        .CommandText = SqlQuery
        .Connection = BMS_APP.cnn
    End With
    With SqlAdepter
        .SelectCommand = SqlCommand
        .Fill(TABLE)
    End With
    Dim crystal As New CrystalReport1
    crystal.SetDataSource(TABLE)
    CrystalReportViewer1.ReportSource = crystal
    CrystalReportViewer1.Refresh()
End Sub

Here Is My Process Of Application

I have clicked on load button and it loads all data from database to datagridview

After that when i click on particular row its display only one row in crystal report but i want to display all current rows which was in datagriwview

Here What's Happen

First I have Clicked ON Row in datagridview

It shows in crystal report one row but i want to print all rows current rows

Please Help what should i do print all current rows thank you

Best Answer

If you want to print all records in your DGV ..

change crystal.SetDataSource(TABLE)

to crystal.SetDataSource(DataGridView1.Datasource)

Related Topic