【发布时间】:2014-01-30 17:19:19
【问题描述】:
我对编程还很陌生。
我不打算使用 Crystal Reports,除非因为许可费用而绝对必要。我也对 .rdlc 进行了一些研究,老实说,这让我很困惑。我不确定如何使用报告向导将我想要的数据放入客户端报告定义中。不过,附带说明一下,我正在处理加密数据。
我正在对我的 DataTable 中的数据进行解密,并希望从提供 DGV 的 DataTable 中生成一份报告并将其显示在 ReportViewer 中。如果有更好的方法请告诉我!
我不确定如何使用 DataTable 作为报表的数据源。这是我的代码:
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
我试过了:
Dim ds As DSReportTest
ds.Tables.Add(dt)
这没有用。我之所以尝试依赖dt,是因为它包含解密后的数据。
【问题讨论】:
-
更新:如果有人想知道我最终是如何做到的,请发表评论,我会发布代码。
标签: vb.net visual-studio-2010 datagridview sql-server-2008-r2