У меня есть 2 подхода для привязки данных к элементу управления ReportViewer.Какой из них лучше?Не могли бы вы дать мне совет?
Подход 1: Использование SqlDataAdapter
Dim dt As DataTable = New DataTable
Dim conn As SqlConnection = New SqlConnection(connString)
Try
conn.Open()
Dim cmd As New SqlCommand(sql, conn)
Dim adapter As New SqlDataAdapter(cmd)
adapter.Fill(dt)
Catch ex As Exception
Finally
conn.Close()
End Try
Dim ds As New ReportDataSource(dataSourceName, dt)
rViewer.LocalReport.DataSources.Clear()
rViewer.LocalReport.DataSources.Add(ds)
rViewer.LocalReport.Refresh()
Подход 2: Использование SqlDataReader
Dim dt As New DataTable()
Dim conn As SqlConnection = New SqlConnection(connString)
Try
conn.Open()
Dim cmd As New SqlCommand(sql, conn)
Dim reader As SqlDataReader = cmd.ExecuteReader()
dt.Load(reader)
reader.Close()
Catch ex As Exception
Finally
conn.Close()
End Try
Dim ds As New ReportDataSource(dataSourceName, dt)
rViewer.LocalReport.DataSources.Clear()
rViewer.LocalReport.DataSources.Add(ds)
rViewer.LocalReport.Refresh()