vb.net下初使用CR9.2请教绑定数据源

zhang_yling 2014-05-08 11:50:23
偶觉得.net2005下自带的CR不好用,安装了CR9.2.2。在数据化报表时发现错误,预览控件显示表格头,但没有详细数据记录。
语句如下:
dim cr_oApp as new CRAXDRT.application
dim cr_oRpt as new CRAXDRT.Report
'报表文件使用‘字段定义’方式,引用rpt2.ttx;包含(name-字符串;user_id-字符串)
Dim conn As New SqlConnection
Dim da As SqlDataAdapter
Dim comm As SqlCommand
Dim ds As DataSet
Dim path, strFileName As String

conn.ConnectionString = "Data Source=(local);Initial Catalog=aaa;Integrated Security=false;User ID=sa;Password=;"

comm = New SqlCommand("select name,user_id from oper", conn)
da = New SqlDataAdapter()
da.SelectCommand = comm

Try
conn.Open()
ds = New DataSet()
da.Fill(ds, "tb1")

path = My.Application.Info.DirectoryPath
path = path.Substring(0, path.LastIndexOf("\") - 3)
strFileName = path & "rpt2.rpt"

CR_oRpt = CR_oApp.OpenReport(strFileName)
CR_oRpt.Database.SetDataSource(ds.Tables(0))

Catch ex As Exception
MessageBox.Show(ex.ToString, "", MessageBoxButtons.OK)
End Try
'初始化预览 CRV控件为Crystal Report Viewer Control 9
CRV.ReportSource = CR_oRpt
CRV.ViewReport()

conn.Close()
...全文
107 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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