2012-01-14 41 views
0

我有Windows應用程序,其中我正在構建數據集與兩個數據表一個是「產品」,其他是「TaxView」。我已經包括示例代碼below.in此代碼我收到錯誤Input array is longer than the number of columns in this table「輸入數組長度超過這個表中的列數」在c#應用程序

public DataTable[] getProductViewDetails(ArrayList ssd,ArrayList tax) 
     { 
      DataTable Products = new DataTable(); 
      DataColumn SalesDetailID = Products.Columns.Add("SalesDetailID", typeof(System.INT32)); 
      DataColumn BrandName = Products.Columns.Add("BrandName", typeof(System.String)); 
      DataColumn ProductName = Products.Columns.Add("ProductName", typeof(System.String)); 
      DataColumn Quantity = Products.Columns.Add("Quantity", typeof(System.INT32)); 
      DataColumn Rate = Products.Columns.Add("Rate", typeof(System.INT32)); 
      DataColumn Per = Products.Columns.Add("Per", typeof(System.String)); 
      DataColumn Discount = Products.Columns.Add("Discount", typeof(System.String)); 


      DataTable TaxView = new DataTable(); 
      DataColumn SalesTaxDetailID = Products.Columns.Add("SalesTaxDetailID", typeof(System.Int32)); 
      DataColumn TaxAmt = Products.Columns.Add("TaxAmt", typeof(System.Int32)); 
      DataColumn Total = Products.Columns.Add("Total", typeof(System.Int32)); 
      DataColumn TaxDesc = Products.Columns.Add("TaxDesc", typeof(System.String)); 
      DataColumn TaxValues = Products.Columns.Add("TaxValues", typeof(System.INT32)); 

      foreach (SalesStructDetails s in ssd) 
      { 
       //int previoustaxdetail; 

       Products.Rows.Add(1,HP, Printer, 2, 2100, pcs, 125); 

       foreach (TaxDetail t in tax) 
       {          
        if (s.SalesDetailId == t.SalesDetailID) 
        { 
         TaxView.Rows.Add(1, 125, 75, VAT, 4); 

        } 
       } 
      } 

      DataTable[] dt = new DataTable[2] { Products, TaxView }; 
      return dt; 
     } 

我得到的錯誤在該行TaxView.Rows.Add(1, 125, 75, VAT, 4);

回答

4

細心觀察 - 要添加的稅收列定義到產品列表中。將它們添加到稅表中。例如:

DataTable TaxView = new DataTable(); 
DataColumn SalesTaxDetailID = Products.Columns.Add(blah); 

應該是;

DataTable TaxView = new DataTable(); 
DataColumn SalesTaxDetailID = TaxView.Columns.Add(blah); 

另外:我沒有notice.Thanks求救考慮使用普通班,而不是數據表

+0

對不起 – sharad 2012-01-14 11:59:52

相關問題