遍历数据集,并将7列中的5列的值应用于活动报表中的文本框



我想遍历dataSet并将每个值应用于活动报表中的文本框。我不知道如果这些文本框需要是一个组/标题区域或什么。我知道下面的代码只检索第一行。我如何遍历所有行并将数据应用于活动报表管理的文本框,以便在组部分

中获得多行?
    Private Sub rptUserCellPhoneSwap_ReportStart(sender As Object, e As System.EventArgs) Handles Me.ReportStart
    Me.PageSettings.Orientation = GrapeCity.ActiveReports.Document.Section.PageOrientation.Landscape
    DateTxt.Text = Now.ToShortDateString & " " & Now.ToShortTimeString
    Dim DataSet = GrabInformation(FirstName, LastName)
    UserTxt.Text = LastName + ", " + FirstName
    'For Each dr As DataRow In DataSet.Tables(0).Rows
    '    OldIMEITxt.Text = DataSet.Tables(0).Rows(dr("OldIMEI")).ToString
    '    NewIMEITxt.Text = DataSet.Tables(0).Rows(dr("NewIMEI")).ToString
    '    ReasonTxt.Text = DataSet.Tables(0).Rows(dr("SwapReason")).ToString
    '    DateRepTxt.Text = DataSet.Tables(0).Rows(dr("DateSwapped")).ToString
    '    ValueTxt.Text = DataSet.Tables(0).Rows(dr("EstimatedAccumulatedValue")).ToString
    'Next
    If Not IsNothing(DataSet) Then
        If DataSet.Tables(0).Rows.Count > 0 Then
            OldIMEITxt.Text = DataSet.Tables(0).Rows(0)("OldIMEI")
            NewIMEITxt.Text = DataSet.Tables(0).Rows(0)("NewIMEI")
            ReasonTxt.Text = DataSet.Tables(0).Rows(0)("SwapReason")
            DateRepTxt.Text = DataSet.Tables(0).Rows(0)("DateSwapped")
            ValueTxt.Text = DataSet.Tables(0).Rows(0)("EstimateAccumulatedValue")
        End If
    End If

End Sub

ActiveReports可以从数据集中读取数据,而无需在代码中添加额外的循环。如果您将数据表返回到报表对象的DataSource属性,那么只需正确设置TextBox控件和GroupHeader节的DataField属性即可在报表中显示数据。呈现引擎将自动遍历所有数据行:

    Private Sub SectionReport1_ReportStart(sender As Object, e As EventArgs) Handles MyBase.ReportStart
    ' bind TextBox controls to fields in table
    Me.txtF1.DataField = "F1"
    Me.txtF2.DataField = "F2"
    ' set the grouping field
    Me.GroupHeader1.DataField = "F2"
    ' set the report data source
    Me.DataSource = GetSampleData().Tables(0)
End Sub
Private Function GetSampleData() As DataSet
    Dim ds = New DataSet()
    Dim dt = ds.Tables.Add("TestData")
    dt.Columns.Add("F1")
    dt.Columns.Add("F2")
    dt.Rows.Add("1", "0")
    dt.Rows.Add("2", "0")
    dt.Rows.Add("1", "1")
    dt.Rows.Add("2", "1")
    Return ds
End Function

如果你喜欢在"半自动模式"下逐行读取数据,那么FetchData事件处理程序可以在这里提供帮助:

    Dim i As Integer
Dim dt As DataTable = Nothing
Private Sub SectionReport2_ReportStart(sender As Object, e As EventArgs) Handles MyBase.ReportStart
    i = 0
    ' bind TextBox controls to fields in table
    Me.txtF1.DataField = "F1"
    Me.txtF2.DataField = "F2"
    ' set the grouping field
    Me.GroupHeader1.DataField = "F2"
    dt = GetSampleData().Tables(0)
End Sub
Private Sub SectionReport2_DataInitialize(sender As Object, e As EventArgs) Handles MyBase.DataInitialize
    Me.Fields.Add("F1")
    Me.Fields.Add("F2")
End Sub
Private Sub SectionReport2_FetchData(sender As Object, eArgs As FetchEventArgs) Handles MyBase.FetchData
    If dt.Rows.Count > i Then
        Me.Fields("F1").Value = dt.Rows(i)(0)
        Me.Fields("F2").Value = dt.Rows(i)(1)
        eArgs.EOF = False
    Else
        eArgs.EOF = True
    End If
    i = i + 1
End Sub
Private Function GetSampleData() As DataSet
    Dim ds = New DataSet()
    Dim _dt = ds.Tables.Add("TestData")
    _dt.Columns.Add("F1")
    _dt.Columns.Add("F2")
    _dt.Rows.Add("1", "0")
    _dt.Rows.Add("2", "0")
    _dt.Rows.Add("3", "1")
    _dt.Rows.Add("4", "1")
    Return ds
End Function

另外,我建议查看ActiveReports安装包中带有运行时数据绑定的示例。这里有一个链接到官方网站的示例描述:释放数据

这就是您如何循环获取所有行,但在本例中,唯一将留在文本框中的数据将是最后一行。

如果你想在指定的文本框中连接每一行信息,那么你应该有这样的信息。

OldIMEITxt.Text = OldIMEITxt.Text & dr("OldIMEI")

循环代码
For each dr as Datarow in DataSet.Tables(0).Rows
   OldIMEITxt.Text = dr("OldIMEI")
   NewIMEITxt.Text = dr("NewIMEI")
   ReasonTxt.Text = dr("SwapReason")
   DateRepTxt.Text = dr("DateSwapped")
   ValueTxt.Text = dr("EstimateAccumulatedValue")
Next

相关内容

  • 没有找到相关文章

最新更新