crystal report和sql命令

时间:2012-05-21 11:56:35

标签: sql vb.net crystal-reports

我在水晶报表中显示联接表中的数据内容时遇到问题 我的SQL查询很好,它显示了我自己的数据,但我填写水晶报告数据源,并显示它晶体重复重复和更多的数据 我的代码是:

   Dim rep As CrystalReport1 = New CrystalReport1()
    Dim objcon = New SqlConnection("data source=(local);initial catalog=hesabres;user id='sa';password='Maysam7026'")
    Dim objcom = New SqlCommand
    Dim objdata As New DataTable
    Dim objdr As SqlDataReader
    objcom.CommandText = " SELECT customer.customer_name, customer.customer_tel, orders.order_stuff_name, orders.order_number" & _
" FROM   hesabres.dbo.orders orders inner JOIN hesabres.dbo.customer customer ON orders.order_customer_id=customer.customer_id"

    objcom.Connection = objcon
    objcon.Open()
    objdr = objcom.ExecuteReader
    objdata.Load(objdr)
    rep.SetDataSource(objdata)
    CrystalReportViewer1.ReportSource = rep

1 个答案:

答案 0 :(得分:1)

尝试更改这两行的顺序 从:

rep.SetDataSource(objdata)
CrystalReportViewer1.ReportSource = rep

为:

CrystalReportViewer1.ReportSource = rep
rep.SetDataSource(objdata)