2011-11-27 91 views
0

我正在开发使用VS2008的窗体应用程序,并尝试使用Crystal ActiveX Report Viewer 11_5(支持Khmer Unicode)查看报告。当运行时我需要更改报表的数据源作为内置在VS 2008中的Crystal Report Viewer可以但我总是得到这个错误短信“尝试读取或写入受保护的内存。这往往表明其他内存已损坏。”Crystal ActiveX Report Viewer 11.5运行时更改数据源

Here is my code: 

    Dim FRM As New frmOtherReport 
    Dim app As New CRAXDDRT.Application 
    Dim rpt As CRAXDDRT.Report 
    Dim tbl As CRAXDDRT.DatabaseTable 
    Dim tbls As CRAXDDRT.DatabaseTables 
    rpt = app.OpenReport(ReportsURL + "rptStudentListAll.rpt")   
    For Each tbl In rpt.Database.Tables 
     tbl.ConnectionProperties.DeleteAll() 
     tbl.ConnectionProperties.Add("Provider", "SQLOLEDB") 
     tbl.ConnectionProperties.Add("Data Source", My.Settings.Datasource) 
     tbl.ConnectionProperties.Add("Initial Catalog", My.Settings.Database) 
     'tbl.ConnectionProperties.Add("Integrated Security", "True") ' cut for sql authentication 
     tbl.ConnectionProperties.Add("User Id", My.Settings.Username) ' add for sql authentication 
     tbl.ConnectionProperties.Add("Password", My.Settings.Password) ' add for sql authentication 
    Next tbl 
    'This removes the schema from the Database Table's Location property. 
    tbls = rpt.Database.Tables 
    For Each tbl In tbls 
     With tbl 
      .Location = .Name 
     End With 
    Next 

    'View the report 
    rpt.Database.Tables(1).SetDataSource(myDataTable) 'error location 
    FRM.AxCrystalActiveXReportViewer1.ReportSource = rpt 
    FRM.AxCrystalActiveXReportViewer1.ViewReport() 
    FRM.Show() 

任何意见赞赏。

回答