2011-11-27 100 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() 

任何意見讚賞。

回答