我有兩種方法將數據綁定到ReportViewer控件。哪一個更好?你能給我一些建議嗎?將數據綁定到ReportViewer控件的最佳方法是什麼? (DataAdapter vs DataReader)
方法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()
方法二:使用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()
非常歡迎您發表評論,接受或索取更多信息。這就是StackOverflow的工作方式。謝謝。 – LeftyX 2011-04-07 07:03:37