关于水晶报表数据显示问题~~~急!!!!!!!!!!

xiangzi630 2007-10-25 09:51:20
初始绑定是:
CrystalReport1 obj = new CrystalReport1();
obj.SetDatabaseLogon("sa", "sa");
this.crystalReportViewer1.ReportSource = obj;
显示的是全部的信息。

我现在加了条件:
CrystalReport1 obj = new CrystalReport1();
obj.SetDatabaseLogon("sa", "sa");
obj.SetDataSource(c.读取(strSQL));
this.crystalReportViewer1.ReportSource = obj;
这里的SQL语句没有问题,我提取出来查看,结果真确,但是这个时候报表显示的还是以前的全部数据

请问这个什么处理呀?
...全文
138 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaoxiaoyang5156 2007-10-25
  • 打赏
  • 举报
回复
把报表文件删掉。重新建一个。
it_gz_xi 2007-10-25
  • 打赏
  • 举报
回复
昨天我在论坛有一位大哥有这样的一段文章。忘记是谁了。。请原著见谅。希望这对你有帮助



向水晶报表传递参数时,要注意的是:必须向服务器的名称、数据库名、登录名、密码传递给报表文件,如果有子报表的话,这些参数也要传递。
下面是我的代码,各位可能要适当修改。
本文有参考网上的一篇文章,但是哪位的我就记不得了,请原作者不要见怪。

Try
Me.Cursor = Cursors.WaitCursor

Dim Num, strRPTFile, str() As String
Dim srv, db, user, pwd As String
Dim sql As String
Dim dsSub As New DataSet

Dim sqlConn As New SqlConnection


If Me.dgrd1.DataSource Is Nothing Then
Exit Function
End If

If Me.dgrd1.SelectedCells.Count <= 0 Then
Exit Function

End If

If Me.dgrd1.CurrentCell Is Nothing Then
Exit Function
End If

Num = Me.dgrd1.Rows(Me.dgrd1.CurrentRow.Index).Cells("Num").Value
If Num Is Nothing Then
Exit Function
Else

str = ConfigurationManager.AppSettings("SqlServer").Split(";")


strRPTFile = GetReportPath("PUR", "PUR_PO.rpt")

For I As Integer = 0 To str.Length - 1
If str(I).IndexOf("=") > 0 Then
If str(I).Split("=")(0).ToUpper = "Server".ToUpper Then
srv = str(I).Split("=")(1)
End If

If str(I).Split("=")(0).ToUpper = "DataBase".ToUpper Then
db = str(I).Split("=")(1)
End If

If str(I).Split("=")(0).ToUpper = "Uid".ToUpper Then
user = str(I).Split("=")(1)
End If

If str(I).Split("=")(0).ToUpper = "Pwd".ToUpper Or str(I).Split("=")(0).ToUpper = "Password".ToUpper Then
pwd = str(I).Split("=")(1)
End If

End If
Next

Dim CMD As System.Data.SqlClient.SqlCommand
Dim sqlAD As New SqlDataAdapter
Dim ds As New DataSet


Dim myReportDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim myParameterValues As New CrystalDecisions.Shared.ParameterValues
Dim myDiscreteValue As New CrystalDecisions.Shared.ParameterDiscreteValue


strRPTFile = GetReportPath("PUR", "PUR_PO.rpt")

sqlConn.ConnectionString = ConfigurationManager.AppSettings("SqlServer")
If sqlConn.State = ConnectionState.Closed Then
sqlConn.Open()
End If


CMD = New SqlClient.SqlCommand("Select_PO", sqlConn)
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandTimeout = 60

CMD.Parameters.Add(New SqlClient.SqlParameter("@Num", SqlDbType.NVarChar, 4000))
CMD.Parameters("@Num").Value = Num


CMD.ExecuteNonQuery()
CMD.Dispose()

sqlAD.SelectCommand = CMD
sqlAD.Fill(ds, "Rptds")


"向子報表傳遞參數
sql = "exec dbo.GetCommpanyInfo"
dsSub = ReturnDataset(sql)


Dim logonInfo As New TableLogOnInfo
Dim table As Table
myReportDoc.Load(strRPTFile)


"设置登录信息
For Each table In myReportDoc.Database.Tables
logonInfo = table.LogOnInfo
With logonInfo.ConnectionInfo
.ServerName = srv
.DatabaseName = db
.UserID = user
.Password = pwd
End With
table.ApplyLogOnInfo(logonInfo)

Next


"向子報表傳遞登錄參數
For I As Integer = 0 To myReportDoc.Subreports.Count - 1

For Each table In myReportDoc.Subreports(I).Database.Tables
With logonInfo.ConnectionInfo
.ServerName = srv
.DatabaseName = db
.UserID = user
.Password = pwd
End With
table.ApplyLogOnInfo(logonInfo)
Next

If myReportDoc.Subreports(I).Name = "CommpanyInfo" Then
myReportDoc.Subreports(I).SetDataSource(dsSub.Tables(0))

End If

Next

myReportDoc.SetDataSource(ds.Tables(0))


My.Forms.Frm_Report.CrystalReportViewer1.ReportSource = myReportDoc
My.Forms.Frm_Report.CrystalReportViewer1.Zoom(1)
My.Forms.Frm_Report.CrystalReportViewer1.DisplayGroupTree = False

Frm_Report.ShowDialog()


End If


Catch ex As Exception
Me.Cursor = Cursors.Default
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "信息提示")
Finally
Me.Cursor = Cursors.Default
End Try

it_gz_xi 2007-10-25
  • 打赏
  • 举报
回复
有检查过你查出来的数据集有问题吗?
比如说你数据集的字段和报表的字段不统一,这样就传不过去
xiangzi630 2007-10-25
  • 打赏
  • 举报
回复
刷新了还是不行
it_gz_xi 2007-10-25
  • 打赏
  • 举报
回复
你是刷新了报表再加载还是加载之后再刷新,
我刚刚也遇到这样问题,我刷新了一下就有数据了
Dim rpt As New ReportDocument
rpt.Load("..\..\CrystalReport2.rpt")
rpt.SetDataSource(ds)
Form5.CrystalReportViewer1.ReportSource = rpt
'Form5.CrystalReportViewer1.RefreshReport()

4,819

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧