Help!How to generate a crystal report from gridview data!
i ady can get data in gridview through the code below!
How can i generate a crystal report from this???

Dim sColList, sTableName As String
        Dim DT_Data As New RS_UtilityService.dsSDFSystem.sp_DynamicSQLDataTable
        Dim ds As New DataSet
        Dim table1 As New DataTable



        sTableName = ListColumn.DataSource(0)("TABLE_NAME").ToString

        sColList = "*"
        If ListRptCol.ItemCount > 0 Then
            Dim DT As DataTable = ListRptCol.DataSource
            sColList = ""

            For iCnt = 0 To DT.Rows.Count - 1
                If DT(iCnt)("SOURCE").ToString = "CALC" Then
                    sColList += "|" & DT(iCnt)("COLUMN_NAME").ToString & "=(" & DT(iCnt)("FORMULA").ToString & ")"
                Else
                    sColList += "|" & DT(iCnt)("COLUMN_NAME").ToString
                End If

            Next
            sColList = Mid(sColList, 2)
        End If



        r_sSQL = "Select Top(" & txtRecordNo.Text & ") " & sColList.Replace(CChar("|"), CChar(",")) & " From " & sTableName & _
                 " Where 0=0" & sParameter



        If chkPreviewData.CheckState = CheckState.Unchecked Then r_sSQL += " And 1=0 "
        Try
            DT_Data = RiskkServices.UtilityService.GetDynamicData(r_sSQL)
        Catch ex As Exception
            RiskkCommonLib.RiskkMsg.ShowMsg(ex.Message, "Error", MessageBoxButtons.OK, Utils.MessageBoxExLib.MessageBoxExIcon.Error)
        End Try

        grdReport.DataSource = DT_Data
        grdV.RefreshData()
        grdV.BestFitColumns()

HELP!!!thanks

First create a crystal report and design it in the way you like.
Then add these lines of code for whatever event you like to use for generating the report.
Assuming that DT_Data can be cast as DataTable.

Dim crp As New CrystalReport1
crp.SetDataSource(DirectCast(DT_Data, DataTable))

Do u means like tis?

Dim rpt As New CrystalReport1
        rpt.SetDataSource(DirectCast(DT_Data, DataTable))
        CrystalReportViewer1.ReportSource = rpt

nid add any reference?bcoz there show type crystalReport1 is not defined
thanks

Yeah. You have to create it first.
In the solution explorer, right-click, add new item. Crystal Report.

can i replace with the code below?

Dim rpt As ReportDocument = New ReportDocument()
        rpt.Load("D:\CrystalReportForm.rpt")
        rpt.SetDataSource(DirectCast(DT_Data, DataTable))
        CrystalReportViewer1.ReportSource = rpt

but why rpt.SetDataSource(DirectCast(DT_Data, DataTable))
show an error"the report has no tables"

Thanks

It could be because DT_Data is not exactly a .NET DataTable.
Which is why I used a DirectCast statement.
But obviosly it doesn't work, so you'll have to replace DT_Data with a normal DataTable.

I noticed in your code that you have declared tabl1 as a DataTable, but it's not being used.

Due to the grdreport.DataSource = DT_Data, i wan display the data from grdreport to crystal report.so how to replace DT_Data with normal Data Table?
i'm a newbie so not really understand!can u giv some example o reference?
thanks

I don't even know what RS_UtilityService is, so I can't give any examples of how to convert.
But I thought of another solution that MIGHT work.

rpt.SetDataSource(grdreport.DataSource)

If this doesn't work, then I must tell you that I cannot help you any further.
Because, I'm quite a newbie regarding Crystal Reports myself.

This article has been dead for over six months. Start a new discussion instead.