2012-01-14 24 views
0

我使用代碼在報告中的值textbox2.text和使用類似下面的代碼DirectCast如何實現

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 

回答

0

你應該做這樣的:

你上面添加此R代碼裏面

Imports CrystalDecisions.CrystalReports.Engine 

然後

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