简体   繁体   English

如何用vb.net在水晶报表中填充sql查询结果

[英]How to populate sql query result in crystal report with vb.net

I am new to work with vb.net and crystal report I searched many links while failed to populate or load SQL query result on crystal report?我是 vb.net 和 Crystal Report 的新手 我搜索了许多链接,但未能在 Crystal Report 上填充或加载 SQL 查询结果?

here is the code to load query result on grid-view这是在网格视图上加载查询结果的代码

 Dim cc As SqlConnection = New SqlConnection(" Server=(localdb)\Projects;Database=question;Uid=sa;Pwd=12345;")
        Dim cmd As SqlCommand = New SqlCommand("SELECT  * FROM tencmpC1 where qnumber in 1,2,3 ", cc)
             Dim adp, As New SqlDataAdapter(cmd)
        cmd.Connection.Open()Dim ds As DataTable = New DataTable
           adp.Fill(ds)
        grid.ItemsSource = ds.DefaultView
        cmd.Connection.Dispose()

But what i did with grid-view same that i want with crystal report ?但是我用 grid-view 做了什么和我想要的水晶报告一样?

Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM tencmpC1 where qnumber in 1,2,3 ", cc) Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM tencmpC1 where qnumber in 1,2,3 ", cc)

may be number changed every time 1,2,3 or 4,85,9 or 54,96,400 .每次 1,2,3 或 4,85,9 或 54,96,400 时可能会更改数字。

here I only need guidance on loading SQL query result on crystal report?在这里我只需要在水晶报表上加载 SQL 查询结果的指导?

thanks in advance.提前致谢。

sorry if its hard to understand I try my level best to express my self what I want.对不起,如果它很难理解我会尽我所能来表达我想要的东西。

在此处输入图片说明

You have two ways to do this : 您有两种方法可以做到这一点:

  1. Crystal Report Parameters : User can manually pass the parameters to the crystal report at runtime. Crystal Report参数 :用户可以在运行时手动将参数传递给Crystal报表。 Using this Parameters , you can pass the desired values to the Crystal Reports. 使用此Parameters ,可以将所需的值传递给Crystal Reports。 In your example, to SQL Query. 在您的示例中,执行SQL查询。

  2. Create a query which accepts data as parameter. 创建一个接受数据作为参数的查询。 And while loading the Crystal Report, Fill data Adapter with that query which will ultimately fill the Crystal Report according to the query. 在加载Crystal Report时,使用该查询填充数据适配器,最终将根据查询填充Crystal Report。

We have Try below code, here show only first record but I want show all Listbox 's selected items record.我们尝试了下面的代码,这里只显示第一条记录,但我想显示所有 Listbox 的选定项目记录。 please help me .I am new here..请帮助我。我是新来的。

Code:--代码: -

connection_open() Dim dt As New DataTable cmd = New SqlCommand("select * from Tbl_Employee where ID = '" + ListBox8.Selecteditem + "'", cnn) Dim adp As New SqlDataAdapter(cmd) adp.Fill(dt) connection_close() connection_open() Dim dt As New DataTable cmd = New SqlCommand("select * from Tbl_Employee where ID = '" + ListBox8.Selecteditem + "'", cnn) Dim adp As New SqlDataAdapter(cmd) adp.Fill(dt) connection_close( )

    Dim cr As New Employee_Masterreport
    cr.SetDataSource(dt)

    EmpMstReport.CrystalReportViewer1.ReportSource = cr
    EmpMstReport.CrystalReportViewer1.Refresh()
    EmpMstReport.Show()
        Me.Hide()

This is my report filter section这是我的报告过滤器部分

This is my output section这是我的输出部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM