簡體   English   中英

錯誤:從字符串加載報告轉換失敗到類型整數無效

[英]Error:conversion from string load report failed to type integer is not valid

有一個搜索按鈕,用於查看datagridview上的報告使用year..so當數據庫中有更多項目對應它年份(比如2012)...填充datgridview拋出上述異常,問題發生時嘗試連接水晶報告,它顯示錯誤...請記住,我只有在我的數據庫中有更多記錄(正好超過100行)時才會面臨這個問題...當我從數據庫中刪除幾行時,它工作正常。 。我創建了一個表並將該表添加到數據集中,然后將該table1指定為crystal report的數據源

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

嘗試評論所有這些行

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

然后逐個取消注釋。

我自己解決了這個問題,問題是,如果有關於數據庫的更多數據,我的水晶報告會多次加載,因為我在formcall()方法中設置了水晶報表的數據源,這個方法調用的多於當每一行添加到表時100次,所以這個相同的報告加載了很多次。我在new方法中聲明了“setDatasource(ds.table(1))”,只有在將所有行添加到click_button事件中之后才會調用它。數據源表...感謝您的所有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM