2012-04-17 53 views
0

有一個搜索按鈕,以查看datagridview使用year..so時的報表,當數據庫中有更多的項目在那裏對應它一年(說2012年)..上面的例外是通過填充datgridview引發的,當它試圖連接水晶報表時發生問題,它顯示錯誤...請記住,只有在我的數據庫中有更多記錄時,我纔會面對此問題(正好超過100行)......當我從數據庫中刪除幾行,它的工作原理fine..I已經創建了一個表,並補充說,表中的數據集,然後分配了表1作爲數據源的Crystal報表錯誤:從字符串加載報告轉換失敗,鍵入整數無效

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 
+0

哪裏是代碼? – 2012-04-17 12:34:10

回答

1

我自己解決了這個問題,問題是,如果數據庫中有更多的數據,我的水晶報表會多次加載,因爲我已經在formcall()方法裏設置了水晶報表的數據源,這個方法當每行添加到表中時調用的次數超過100次,因此同一個報告將多次加載。我在新方法中聲明瞭「setDatasource(ds.table(1))」,該方法僅在添加後才由click_button事件調用所有行到數據源表..感謝您的所有幫助

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 

然後取消一個一個註釋。

+0

我甚至沒有註釋上面的所有內容,它仍然顯示相同的錯誤,即使它是空白的(即t = ds1.Tables.Add(「DataTable1」) r = t.NewRow()t.Rows.Add(r ) Dim objRpt As New CrystalReport2)所有r(「xx ..」)和t.Columns.Add(「invoiceno」,Type.GetType(「xxx」))取消註釋 – suhail 2012-04-18 14:56:51

+0

向數據表添加新行時發​​生問題超過100次(超過100行) – suhail 2012-04-18 15:00:25

相關問題