如何向数据集添加数据表值 [英] How to add datatable values to dataset

查看:57
本文介绍了如何向数据集添加数据表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将数据表值添加到数据集中.当我运行程序时,它表明未设置参数值.我正在使用水晶报表(带有子报表).

这是我的代码:

Hi,

I want to add the datatable values to the dataset. When I am running the program it shows that the parameter values are not set. I am using crystal report(with subreport).

Here is my code:

For Each row As DataRow In dt2.Rows
            rpt = ViewState("rpt")
            Dim drt As DataRow
            drt = rpt.NewRow
            Dim uniq As String = GetUniqueCode()
            drt("Entitlement Number") = uniq
            drt("Customer Name ") = row("cust_name")
            drt("Customer Address1") = row("cust_add1")
            drt("Customer Address2") = row("cust_add2")
            drt("Customer City") = row("cust_city")
            drt("Customer State") = row("Cust_State")
            drt("UPS Model") = row("item_cd")
            drt("Serial Number") = row("lot_no")
            drt("ASP Name") = row("branch_name")
            drt("ASP Address1") = row("branch_add1")
            drt("ASP Address2") = row("branch_add2")
            drt("ASP Address3") = row("branch_add3")
            drt("ASP City") = row("branch_city")
            drt("ASP State") = row("ASP_STATE")
            drt("EntitledEffectiveDate") = row("doc_dt")
            ''Dim dt As Date = New Date(row("doc_dt"))
            drt("EntitledEndDate") = Convert.ToDateTime(row("doc_dt")).AddMonths(3)
            rpt.Rows.Add(drt)
            ViewState("rpt") = rpt
        Next
        DS1.Tables.Add(rpt)
        CrystalReportViewer1.Visible = True
        CrystalReportSource1.ReportDocument.SetDataSource(rpt)
        CrystalReportViewer1.ReportSource = CrystalReportSource1
        CrystalReportViewer1.DataBind()

推荐答案



在查看您的代码时,我注意到
客户名称" 末尾有一个空格.我认为您应该删除
空间,因为它会导致运行时编译出错.同样在创建
时 在DataSet中的column字段中,您必须注意将空格放在
列字段的末尾.

我已经修改了您的代码.
如果有帮助,您可以尝试一下...

Hi,

As I review with your code, I notice that the
"Customer Name " has a space at end. I think you should remove the
space because it causes an error in runtime compilling. Also when creating
the columns fields in your DataSet, you must aware of of puting the space at the
end of your column fields.

I had revised your code.
You may try this if it could help...

Dim rptLoc As String = Server.MapPath("") + "\Reports\AspSample.rpt"
Dim crpt As ReportDocument = New ReportDocument()
crpt.Load(rptLoc)
Dim ds As New DataSet1
crpt.SetDataSource(ds)

Dim dt2 As New DataTable()
ds.MyDatasetTable.Clear()
For Each row As DataRow In dt2.Rows
   Dim drt As DataRow
   drt = ds.MyDatasetTable.NewRow()
   'Dim uniq As String = GetUniqueCode()
   'drt("Entitlement Number") = uniq
   drt("Customer Name") = row("cust_name")
   drt("Customer Address1") = row("cust_add1")
   drt("Customer Address2") = row("cust_add2")
   drt("Customer City") = row("cust_city")
   drt("Customer State") = row("Cust_State")
   drt("UPS Model") = row("item_cd")
   drt("Serial Number") = row("lot_no")
   drt("ASP Name") = row("branch_name")
   drt("ASP Address1") = row("branch_add1")
   drt("ASP Address2") = row("branch_add2")
   drt("ASP Address3") = row("branch_add3")
   drt("ASP City") = row("branch_city")
   drt("ASP State") = row("ASP_STATE")
   drt("EntitledEffectiveDate") = row("doc_dt")
   'Dim dt As Date = New Date(row("doc_dt"))
   drt("EntitledEndDate") = Convert.ToDateTime(row("doc_dt")).AddMonths(3)
   ds.MyDatasetTable.Rows.Add(drt)
Next
CrystalReportViewer1.ReportSource = crpt



注意:"MyDatasetTable" 是我在
中创建的表 数据集1.另请注意,我所拥有的Crystal Report
定位为"\ Reports \ AspSample.rpt"

问候,

代数



Note: That the ''MyDatasetTable'' is the table I had created in the
DataSet1. Also note that the Crystal Report that I had
targeted is "\Reports\AspSample.rpt"

Regards,

Algem


这篇关于如何向数据集添加数据表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆