编辑:为了清楚起见更新了问题:我需要在内存中将SSRS字节流反序列化为数据集。
我需要从VB.Net获取SSRS报告并将结果导入数据集。我可以读取和写入XML文件,但由于某种原因,我的大脑正在打破将XML报告直接放入数据集中,以便我可以操纵它。
我可以获取报告并将其流式传输到XML文件:
Public Sub GetReportNames(serverName As String)
Dim rs As New ReportingService2010()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim items As CatalogItem() = Nothing
' Retrieve a list of all items from the report server database.
Try
items = rs.ListChildren("/", True)
Catch e As SoapException
MessageBox.Show(e.ToString())
End Try
' Serialize the contents as an XML document and write the contents to a file.
Try
Dim fs As New FileStream("ReportNames.xml", FileMode.Create)
Dim writer As New XmlTextWriter(fs, Encoding.Unicode)
Dim serializer As New XmlSerializer(GetType(CatalogItem())) ''
serializer.Serialize(writer, items)
'MessageBox.Show("Report names successfully written to a file.")
writer.Close()
Catch e As Exception
MessageBox.Show(e.ToString())
End Try
End Sub
我可以将XML文件读入VB.net数据集:
Public Sub FileToDataset()
' Serialize the contents as a Dataset
Dim myXMLfile As String = "C:\MyFile.xml"
Dim ds As New DataSet()
' Create new FileStream with which to read the schema.
Dim fsReadXml As New System.IO.FileStream(myXMLfile, FileMode.Open)
ds.ReadXml(fsReadXml)
End Sub
对于我的项目,我首先获取报告名称,然后继续获取每个报告的参数,然后继续调用报告。我有每个步骤的简单示例代码,但目前它都涉及写入磁盘上的XML文件...
编辑:看起来我应该能够从CatalogItem做我需要做的事情。基本上我想将报表名称加载到TreeView中,因此CatalogItem应该没问题。
答案 0 :(得分:0)
因此,正如您在此处看到的,答案是将SSRS报告呈现为result()类型为Byte,移至MemoryStream,然后将这些流ReadXml流入数据集。也许有人可以让这个例子更简单,我把它从一些非常复杂的东西中拉出来。
Public Sub fillADatasetFromRdl
Const ReportName As String = "My Report Name"
Private _reportNamePath As String = "/Optional SSRS Directory/" + ReportName
Private _formatXml As String = "XML"
' Prepare report parameter lists.
Private parametersRdl(4) As ParameterValue
' Set RDL parameters
parametersRdl(0) = New ParameterValue()
parametersRdl(0).Name = "StartDate"
parametersRdl(0).Value = "[Current Date].[YearMonthDate].[Month].&[2012-10-01T00:00:00]"
parametersRdl(1) = New ParameterValue()
parametersRdl(1).Name = "EndDate"
parametersRdl(1).Value = "[Current Date].[YearMonthDate].[Month].&[2012-12-01T00:00:00]"
parametersRdl(2) = New ParameterValue()
parametersRdl(2).Name = "ProvidersProviderLocation"
parametersRdl(2).Value = "[Stores].[Store Location].[Stores].&[123456]"
parametersRdl(3) = New ParameterValue()
parametersRdl(3).Name = "ProviderGroupName"
parametersRdl(3).Value = "Enterprise Report"
' Load dev dataset
Dim devDataSet As New DataSet
Dim rs As New ReportExecutionService
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
' Render arguments
Dim result As Byte() = Nothing
Dim historyID As String = Nothing
Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
Dim encoding As String = ""
Dim mimeType As String = ""
Dim warnings As shpdevdb01_Execution_Service.Warning() = Nothing
Dim reportHistoryParameters As MyServer_Management_Service.ParameterValue() = Nothing
Dim streamIDs As String() = Nothing
Dim execInfo As New ExecutionInfo()
Dim execHeader As New ExecutionHeader()
Dim SessionId As String
Dim extension As String = ""
rs.ExecutionHeaderValue = execHeader
execInfo = rs.LoadReport(reportNamePath, historyID)
rs.SetExecutionParameters(parameters, "en-us")
SessionId = rs.ExecutionHeaderValue.ExecutionID
Try
result = rs.Render(format, devInfo, extension, _
encoding, mimeType, warnings, streamIDs)
execInfo = rs.GetExecutionInfo()
Dim bytes() As Byte = result
Dim s As New System.IO.MemoryStream(bytes)
dsDevData.ReadXml(s)
Catch e1 As SoapException
End Try
Catch e As Exception
End Try
End Sub