0
我有一個SQL表名Patient_Detail
,我想用水晶報表填報,但錯誤是Object reference not set to an instance of an object.
,在rd.Load("C:\Users.....
如何將crystalreportviewer與數據庫連接?
Dim dap As SqlDataAdapter
Dim dat As DataTable
Dim bds As BindingSource
Dim cmd As SqlCommand
Dim ds As DataSet
Dim rd As ReportDocument
Private Sub Report_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cn.Open()
cmd = New SqlCommand
dap = New SqlAdapter
ds = New DataSet
rs = New ReportDocument
cmd.Connection = cn
cmd.CommandText = "SELECT * FROM Patient_Detail"
dap.SelectCommand = cmd
dap.Fill(ds, "Patient_Detail")
rd.Load("C:\Users\Hou Chandara\documents\visual studio 2013\Projects\WindowsApplication1\WindowsApplication1\MyReport.rpt")
rd.SetDataSource(ds)
CrystalReportViewer1.ReportSource = rd
CrystalReportViewer1.RefreshReport()
cn.Close()
End Sub