DirectCast如何实现

时间:2012-01-14 07:39:20

标签: vb.net crystal-reports

我在报告中使用代码值textbox2.text并使用下面的代码

DirectCast(GL2.Section1.ReportObjects("txtfrmDt"), CrystalDecisions.CrystalReports.Engine.TextObject).Text = TextBox2.Text

textbox2在运行时采用各种值,但是当我运行代码时,它只显示最终值,不显示中间值 整个情况如下

bdcon.Open()
Dim QueryString1 As String
Dim QueryString2 As String
Dim y As Integer
y = ComboBox1.Items.Count
If ComboBox1.Text = "" Then
    Dim dsf As DataSet = New DataSet()
    For index As Integer = 0 To y - 1

        Dim Cmd As New SqlCommand("select acname,amt,pamt,newdt from tr_cashbook where newdt BETWEEN  @date1 AND @date2 AND acname='" + ComboBox1.Items.Item(index) + "' ORDER BY acname ASC,newdt ASC", bdcon)
        Cmd.Parameters.Add("@date1", SqlDbType.DateTime).Value = DateTimePicker1.Value
        Cmd.Parameters.Add("@date2", SqlDbType.DateTime).Value = DateTimePicker2.Value
        Dim Adapter As SqlDataAdapter = New SqlDataAdapter(Cmd)
        Dim ds As DataSet = New DataSet()
        If (index = 0) Then
            dsf = ds
            Adapter.Fill(dsf, "Tr_Cashbook")
                           Else
            dsf.Merge(ds, True)
            Adapter.Fill(dsf, "Tr_Cashbook")
        End If
        If (index = y - 1) Then
            Adapter.Fill(dsf, "Tr_Cashbook")
            Ad.Fill(opd, "temp")
            GL2.Load()
            GL2.SetDataSource(dsf)
            GL2.SetDataSource(opd)
            CrystalReportViewer1.ReportSource = GL2
        End If
        QueryString1 = "select SUM(amt) as a, SUM(pamt) as b from tr_cashbook where newdt <='" + DateTimePicker1.Value + "'and acname ='" + ComboBox1.Items.Item(index) + "'"
        Dim mycommand As New SqlCommand(QueryString1, bdcon)
        MyReader = mycommand.ExecuteReader()
        While MyReader.Read
            If IsDBNull(MyReader("a")) Then
                TextBox4.Text = "0.00"
            Else
                TextBox4.Text = MyReader("a")
            End If
            If IsDBNull(MyReader("b")) Then
                TextBox5.Text = "0.00"
            Else
                TextBox5.Text = MyReader("b")
            End If
            TextBox8.Text = TextBox5.Text - TextBox4.Text
                DirectCast(GL2.Section2.ReportObjects("T3"), CrystalDecisions.CrystalReports.Engine.TextObject).Text = TextBox5.Text//code this not working 
        End While
        MyReader.Close()
    Next
    CrystalReportViewer1.ReportSource = GL2

1 个答案:

答案 0 :(得分:0)

你应该这样做:

在代码顶部添加此内容

Imports CrystalDecisions.CrystalReports.Engine

然后

Dim objText As TextObject = CType(rptFile.ReportDefinition.Sections(2).ReportObjects("T3"), TextObject)
objText.Text = "VALUE HERE"