Dear Frens,

I m beginner in VB.net.

I have developed an Address Management System where I want to add my searched grid into Crystal Report.
Unfortunately, I don't know code to make report from datagrid. or certain data set. I have succeeded in making report from primary dataset from crystal report by designining manually.

So, please help me make report from data grid searched . I would be very grateful if u help me.

my code for datagrid is as follows;

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Db1DataSet1.Clear()
        Dim conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;data source=K:\Database\db1.mdb"
        Dim con As OleDb.OleDbConnection = New OleDb.OleDbConnection(conStr)
        Dim S As String
        Dim datagrid1 As New DataGrid
        S = "select * from add1 where lname='" & TextBox1.Text & "'"
        Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(S, con)
        da.Fill(Db1DataSet1, "add1")
        datagrid1.DataSource = Db1DataSet1.DefaultViewManager

    End Sub

I want to add following data grid into crystal report viewer. but I don't know the code

Please help

Anticipating the help

Sincerly

Kshiteesh

Dani AI

Generated

A reliable way to show the searched rows in a Crystal Report is to design the report against a schema (a typed ADO.NET DataSet/XSD) and then "push" the runtime DataTable/DataSet into the report. That avoids schema mismatches and lets the report layout remain exactly as you designed it. As noted, decide whether you want the report to pull from the DB at runtime or for your code to push the filtered result — pushing is simpler when you already have search results in a DataTable.

Steps to follow:

  1. Create an XSD in the project that defines the table/fields the report will use.
  2. In the Crystal Report designer choose Project Data -> ADO.NET DataSets and base the report on that XSD.
  3. At runtime fill a DataTable/DataSet with the search (use parameterized queries, not string concatenation), then call ReportDocument.SetDataSource(...) and assign the report to the CrystalReportViewer.

Example (VB.NET) — fill and push the searched rows into the report:

Dim ds As New DataSet()
Using cn As New OleDb.OleDbConnection(connectionString)
    Using cmd As New OleDb.OleDbCommand("SELECT * FROM add1 WHERE lname = ?", cn)
        cmd.Parameters.AddWithValue("?", TextBox1.Text)
        Dim da As New OleDb.OleDbDataAdapter(cmd)
        da.Fill(ds, "add1")
    End Using
End Using

Dim rpt As New MyCrystalReport()   ' designed against your XSD
rpt.SetDataSource(ds)
CrystalReportViewer1.ReportSource = rpt

If the DataGrid already holds the filtered data you can push that directly:

Dim dv As DataView = CType(DataGrid1.DataSource, DataView)
Dim dt As DataTable = dv.ToTable()
rpt.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rpt

Troubleshooting/cautions: use parameterized queries (OleDb uses positional "?" parameters), be sure the XSD table name and field names match exactly, do not create a new local DataGrid and bind that (bind the form’s grid or use the DataTable directly), and call SetDataSource before assigning ReportSource. For background on typed DataSets see .

Recommended Answers

All 2 Replies

you want to display it self on the report view or the data in the grid . If u wan tthe data then u need to dynamically frame the query at runtime.

I want to display it according to my designof report in the reportview. So please tell me how can I dynamically frame the query at runtime??

thanks n anticipating...

regards
Kshiteesh

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.