Mark C.
Mark C.

Reputation: 6460

Create report from Bound DataTable

I'm fairly new to programming.

I don't plan on using Crystal Reports unless it is absolutely necessary because of license fees. I have also looked into .rdlc a little bit and to be honest it confused me. I was not sure how to get the data I wanted into the Client Report Definition using the Report Wizard. As a side note, though, I am dealing with encrypted data.

I am decrypting data in my DataTable, and would like to make a report out of the DataTable that feeds a DGV and show it in a ReportViewer. If there is a better way please let me know!

I am not sure how to use the DataTable as the data source for the report. Here ismy code for both:

    Dim dt As DataTable = ds.Tables(1)
    ds.DataSetName = "DataSetReport"
    dt.TableName = "DataTable1"


    If SearchFirsttxt.Text = "" Then
        SqlCommand.CommandText = "Select * FROM PARTICIPANT WHERE LAST_NM_TXT = '" & eLast & "';"
    ElseIf SearchLastTxt.Text = "" Then
        SqlCommand.CommandText = "Select * FROM PARTICIPANT WHERE FIRST_NM_TXT = '" & eFirst & "';"
    Else
        SqlCommand.CommandText = "Select * FROM PARTICIPANT WHERE FIRST_NM_TXT = '" & eFirst & "' and LAST_NM_TXT = '" & eLast & "';"
    End If
    'SQL Command returns rows where values in database and textboxes are equal

    SearchFirsttxt.Text = ""
    SearchLastTxt.Text = ""

    dFirst = clsEncrypt.DecryptData(eFirst) 'Decrypts the value entered into the SearchFirsttxt
    dLast = clsEncrypt.DecryptData(eLast)   'Decrypts the value entered into the SearchLasttxt


    Dim myAdapter As New SqlDataAdapter(SqlCommand) 'holds the data
    myAdapter.Fill(dt) 'datatable that is populated into the holder (DataAdapter)
    DataGridView1.DataSource = dt 'Assigns source of information to the gridview (DataTable)

    Try
        For i As Integer = 0 To dt.Rows.Count - 1
            dt.Rows(i)("FIRST_NM_TXT") = clsEncrypt.DecryptData(dt.Rows(i)("FIRST_NM_TXT"))
            dt.Rows(i)("LAST_NM_TXT") = clsEncrypt.DecryptData(dt.Rows(i)("LAST_NM_TXT"))
        Next
    Catch ex As Exception
        MessageBox.Show("Either the first name or last name did not match. Please check your spelling.")
    End Try

I've tried:

Dim ds As DSReportTest
ds.Tables.Add(dt)

which didn't work. The reason I am trying to rely on dt is because it contains the decrypted data.

Upvotes: 0

Views: 450

Answers (2)

iDev
iDev

Reputation: 478

If you are using vs 2010, you should not have a license issue using crystal reports when deploying an application. I assume it's not server based redistribution.

http://www.sap.com/solution/sme/software/analytics/crystal-visual-studio/implement/licensing.html

Upvotes: 1

Junaith
Junaith

Reputation: 3388

Printing DataGridView using PrintDocument could be tedious. Refer this codeproject article to get an idea.

You can also use the DataGridView clipboard content to get the formatted values into clipboard and copy into some excel file. The below MSDN link has some example for getting clipboard content from DataGridView.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.getclipboardcontent%28v=vs.110%29.aspx

Upvotes: 1

Related Questions