在上一篇文章中,我们讲到了如何利用CrystalReport提供的API登录到报表服务器,今天我们讲解,在登录到服务器之后如何获取报表服务器中的数据。 如何获取报表服务器上的报表,在这里我采取的是采用的是CrystalReport中的"InfoStore"API所提供的QUERY方法来查询报表的方式获取的,这里主要又涉及到了数据库的查询语句的组织,关于数据库的查询,不是我们这里所要讨论的问题,在此略过。下面,我们借助于具体的代码,来分析Query方法如何使用。 '//The search event Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click 'Clear the list box Me.lstResults.Items.Clear() Dim reportName As String = String.Empty Dim strQuery As String = String.Empty strQuery = "select * from CI_INFOOBJECTS where SI_INSTANCE = 1 and SI_RECURRING = 1 and SI_NAME='" + Me.txtSI_NAME.Text + "'" 'Select the reports by the strQuery m_infoReports = ceInfoStore.Query(strQuery) 'Release the control right Application.DoEvents() 'Validate the results count. 'If the count less than 1 then show message "There is 0 record(s)" and exit the program If m_infoReports.Count < 1 Then Me.lSearchResult.Text = "There are " + m_infoReports.Count.ToString() + " record(s)" Return End If Me.btnSaveFile.Enabled = True Me.lSearchResult.Text = "There are " + m_infoReports.Count.ToString() + " record(s)" 'About all the InfoObject in the InfoObject collection 'Add their names to the listbox For Each m_infoReport In m_infoReports Application.DoEvents() ProgressCount() reportName = m_infoReport.ID.ToString() + "->" + m_infoReport.Title Me.lstResults.Items.Add(reportName) Next End Sub 在上述的代码中,查询语句strQuery 后面的条件,是每一个我们要设置的参数,比如SI_INSTANCE = 1表示的是这个Instance是子文件.InfoStore.Query()方法的返回值是一个Report集合,所以,我们定义了一个m_infoReports 数组变量来存放方法的返回值,最后使用一个Foreach循环,来遍历数组中的报表内同,并把相关的数据写入到ListView中。 在这两篇中,一直没有提到过所使用的技术平台,这里所使用的技术平台是:VS2003+vb.net |