0

有一个搜索按钮可以使用年份查看关于 datagridview 的报告。所以当数据库中的项目越多时,它对应的年份(比如 2012 年)...上述异常是通过填充 datgridview 引发的,当它尝试时会出现问题连接水晶报表,它显示错误...请记住,只有当我的数据库中有更多记录(正好超过 100 行)时,我才会遇到这个问题...当我从数据库中删除几行时,它工作正常。 .我创建了一个表并将该表添加到数据集中,然后将该表分配为水晶报表的数据源

Public Class crystalform1

Dim r As DataRow
Dim t As DataTable
Dim ds1 As New DataSet1()
Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.



    t = ds1.Tables.Add("DataTable1")


    t.Columns.Add("invoiceno", Type.GetType("System.Int32"))
    t.Columns.Add("customer_name", Type.GetType("System.String"))
    t.Columns.Add("customer_phonenumber", Type.GetType("System.Int32"))
    t.Columns.Add("date", Type.GetType("System.String"))
    t.Columns.Add("product_item", Type.GetType("System.String"))
    t.Columns.Add("bookno", Type.GetType("System.Int32"))
    t.Columns.Add("serialno", Type.GetType("System.Int32"))
    t.Columns.Add("price", Type.GetType("System.Single"))
    t.Columns.Add("quantity", Type.GetType("System.Int32"))

    t.Columns.Add("discount", Type.GetType("System.Int32"))

    t.Columns.Add("paymentby", Type.GetType("System.String"))
    t.Columns.Add("checkno", Type.GetType("System.Int32"))
    t.Columns.Add("checkdate", Type.GetType(" System.String"))
    t.Columns.Add("total", Type.GetType("System.Single"))
    t.Columns.Add("totalamount", Type.GetType("System.Single"))
End Sub
 Sub formcall(ByVal invoiceno As Integer, ByVal date1 As Date, ByVal customername As String, ByVal customerphone As Integer, ByVal product As String, ByVal bookno As Integer, ByVal serialno As Integer, ByVal price As Single, ByVal quantity As Integer, ByVal discount As Integer, ByVal payment As String, ByVal checkno As Integer, ByVal checkdate As String, ByVal total As Single, ByVal totalamount As Single)
    ' This call is required by the designer.
    If IsDate(checkdate) Then
        CType(checkdate, Date).ToShortDateString()
    End If


    r = t.NewRow()
    r("invoiceno") = invoiceno
    r("customer_Name") = customername
    r("customer_Phonenumber") = customerphone
    r("date") = date1.ToShortDateString
    r("product_item") = product
    r("bookNo") = bookno
    r("serialNo") = serialno
    r("price") = price
    r("quantity") = quantity
    r("discount") = discount
    r("paymentby") = payment
    r("checkno") = checkno
    r("checkdate") = checkdate
    r("total") = total
    r("totalamount") = totalamount

    t.Rows.Add(r)
    Dim objRpt As New CrystalReport2


 Try
            objRpt.SetDataSource(ds1.Tables(1))
            CrystalReportViewer1.ReportSource = objRpt /*exception is showing here*/
        Catch ex As Exception
            MsgBox("Report Error", ex.Message())
        End Try



End Sub
4

2 回答 2

1

尝试评论所有这些行

r("invoiceno") = invoiceno
r("customer_Name") = customername
r("customer_Phonenumber") = customerphone
r("date") = date1.ToShortDateString
r("product_item") = product
r("bookNo") = bookno
r("serialNo") = serialno
r("price") = price
r("quantity") = quantity
r("discount") = discount
r("paymentby") = payment
r("checkno") = checkno
r("checkdate") = checkdate
r("total") = total
r("totalamount") = totalamount

然后一一取消注释。

于 2012-04-17T14:56:01.560 回答
1

我自己解决了这个问题,这里的问题是,如果数据库上有更多的数据,我的水晶报表会被加载很多次,因为我在 formcall() 方法中设置了水晶报表的数据源,这个方法调用的次数超过每行添加到表中 100 次,所以同一个报告加载了很多次。我在新方法中声明了“setDatasource(ds.table(1))”,只有在将所有行添加到表中后才会由 click_button 事件调用数据源表..感谢您的帮助

于 2012-04-18T15:22:38.070 回答