无法将数据导入水晶报表 [英] Unable to import Data into crystal report

查看:104
本文介绍了无法将数据导入水晶报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是VB.net的新手,我不确定是否在某个地方犯了错误.

我正在尝试搜索订单号,并将其放入水晶报表中.为此,我试图为我的报告创建一个临时数据集.
主数据集名称= testdatadataset

我尝试编写一个函数,但是它仍然不能通过搜索选项提取数据.

我正在做错事,但无法找出问题所在.

我的代码在下面.

Hello All,

I am a newbie to VB.net and i am not sure if I am making mistake somewhere.

I am trying to search for a orderid and pull the same into a crystal report. For this i am trying to create a temp Dataset for my report.
Main dataset name = testdatadataset

I tried writing a function but it is still not pulling up the data with the search option.

There is something wrong that I am doing but unable to find out where.

My Code is below.

Private Sub Generate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Generate.Click
        Dim Gentxt As Integer = TxtOrderID.Text
        Dim SQLGEN As New SqlCommand
        Dim cryRpt As New GenRep
        Dim RetPath As String = Path.GetDirectoryName(Application.ExecutablePath)
        Dim sqlLink = New SqlConnection()
        sqlLink.ConnectionString = ConStr 'I have this in my config file
        Try
            Dim ds As testdataDataSet = GetData()
            cryRpt.Load("F:\Projects\2008 Projects\Test Application\Test Application\Genrep.rpt")
            cryRpt.SetDataSource(ds)
            ReportViewer.ReportSource = cryRpt
            ReportViewer.Refresh()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub



Private Function GetData() As DataSet
        Dim Query As String = "SELECT [ORDERID],[USERNAME],[ORDERDATE],[PRODUCT],[SUPPLYDATE],[SUPPLYQUAN],[TOTSUPPLY],[AMTPAID],[TAKENBY] FROM TESTDATA "
        If TxtOrderID.Text <> "" Then          
            Query += "WHERE ORDERID = " & TxtOrderID.Text & ""
        End If
        Dim Sqlcon As New SqlConnection
        Sqlcon.ConnectionString = ConStr
        Dim sqlda As New SqlDataAdapter(Query, Sqlcon)
        Dim DS As New testdataDataSet
        sqlda.Fill(DS)' if i check in visual studio 2008 dataset analyser, i get all  columns blank.
        Return DS
    End Function



我正在使用Visual Studio 2008 Professional和SQL Server 2008 Express R2

请帮助我.



I am using visual studio 2008 professional and SQL server 2008 express R2

Please help me.

推荐答案

orderID是数字还是字符串?如果是字符串,则可能需要先将其正确格式化,然后再将其与数据库进行比较.例如,如果数据库中的所有内容均为大写,则请确保使用TxtOrderID.Text.ToUpper代替.如果orderID是一个字符串但包含数字值,则可能必须在左边用零填充,或者在某些情况下在左边或右边用空格填充.您应该考虑使用parms提取此数据,而不是允许将用户编写的直接文本放入SQL语句中.它可能导致此处 [
Is orderID a number or a string? If it''s a string you may have to format it properly before comparing it to the database. For example, if in the database everything is in upper case, then make sure to use TxtOrderID.Text.ToUpper instead. If the orderID is a string but holds number values you may have to pad left with zeros or in some cases pad left or right with spaces. You should consider using parms to pull this data instead of allowing direct text written by the user to be put into an SQL statement. It can lead to SQL Injection[^]. Here[^] is a good CP Article about SQL Injection and how to prevent it. Look for where it talks about Parameterized Queries for help with parameters.


我犯了一个小错误,这花费了我很多时间.

1)当您从数据集中提取数据时,我们创建了一个临时表来保存该表(我没有这样做)

2)我们需要传递数据表(在这种情况下为临时表)以显示信息.(我没有这样做)

处理完这两件事后,我的应用"开始显示正确的数据.

我要发布修改后的代码,以供参考.

I made a small mistake which costed me a lot of time.

1) When you pull the data from dataset, we create a temp table to save that (Which i did not do)

2) We need to pass the datatable (Temp Table in this case) to show the information.(Which i did not do)

After taking care of these two things, My App started showing the correct data.

I am posting the code modified also for reference.

Private Sub Generate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Generate.Click
        Dim Gentxt As Integer = TxtOrderID.Text
        Dim SQLGEN As New SqlCommand
        Dim cryRpt As New GenRep
        Dim RetPath As String = Path.GetDirectoryName(Application.ExecutablePath)
        Dim sqlLink = New SqlConnection()
        sqlLink.ConnectionString = ConStr 'I have this in my config file
        Try
            Dim ds As datatable = GetData()
            cryRpt.Load("F:\Projects\2008 Projects\Test Application\Test Application\Genrep.rpt")
            cryRpt.SetDataSource(dt)
            ReportViewer.ReportSource = cryRpt
            ReportViewer.Refresh()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
 

 
Private Function GetData() As DataSet
        Dim Query As String = "SELECT [ORDERID],[USERNAME],[ORDERDATE],[PRODUCT],[SUPPLYDATE],[SUPPLYQUAN],[TOTSUPPLY],[AMTPAID],[TAKENBY] FROM TESTDATA "
        If TxtOrderID.Text <> "" Then          
            Query += "WHERE ORDERID = " & TxtOrderID.Text & ""
        End If
        Dim Sqlcon As New SqlConnection
        Sqlcon.ConnectionString = ConStr
        Dim sqlda As New SqlDataAdapter(Query, Sqlcon)
        Dim DS As New testdataDataSet
        sqlda.Fill(DS)
        Dim dt As DataTable = DS.Tables("Temp Table")
        Return dt
    End Function



这样就行了...

感谢您的回复...



And this worked...

Thanks for your reply guys...


这篇关于无法将数据导入水晶报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆