Dim rpt As New CheckoutReportpreview
Dim cn As SqlConnection
Dim cmd As New SqlCommand
Dim myDA As New SqlDataAdapter
Dim ds As New CheckoutSet
Dim crConnectionInfo As New ConnectionInfo
Try
With crConnectionInfo
.ServerName = "."
.DatabaseName = "Hotel Management System"
.UserID = "sa"
.Password = "s123"
End With
cmd.Connection = cn
cn.Open()
Dim da As New SqlDataAdapter("select * from tblCheckout where CheckoutDate>='" & CDate(Date_from.Value) & "' and CheckoutDate<='" & CDate(Date_to.Value) & "' ", cn)
cmd.Prepare()
cmd.CommandType = CommandType.Text
myDA.SelectCommand = cmd
myDA.Fill(ds, "tblCheckout")
rpt.SetDataSource(ds)
CheckoutReport.Show()
CheckoutReport.CrystalReportViewer1.ReportSource = rpt
cn.Close()
Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
我在这里有一个代码,我想在日期之间显示报告以点击其他形式点击预览按钮,所以我可以帮助我在发送消息时显示
对象引用未设置为对象的实例
答案 0 :(得分:0)
回答你的问题,为什么你没有将对象引用设置为对象的实例&#34;看看你的SqlConnection。你声明它但是永远不会实例化它,所以当你引用它时它是空的/什么都没有给你那个错误。你可能在cn.Open()行上得到它。
变化:
Dim cn As SqlConnection
类似于:
Dim cn As New SqlConnection("server=yourserver;database=yourdatabase;uid=sa=pwd=sa123")