&引用;输入数组长于此表中的列数;在c#应用程序中
我有一个windows应用程序,其中我正在使用两个数据表构建数据集,一个是“Products”,另一个是“TaxView”。我在下面包含了示例代码。在这段代码中,我发现错误&引用;输入数组长于此表中的列数;在c#应用程序中,c#,sql-server-2005,dataset,C#,Sql Server 2005,Dataset,我有一个windows应用程序,其中我正在使用两个数据表构建数据集,一个是“Products”,另一个是“TaxView”。我在下面包含了示例代码。在这段代码中,我发现错误输入数组长于此表中的列数 public DataTable[] getProductViewDetails(ArrayList ssd,ArrayList tax) { DataTable Products = new DataTable(); DataColu
输入数组长于此表中的列数
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(1125,75,VAT,4)行中遇到错误代码>仔细查看-您正在将税列定义添加到products表中。将它们添加到税表中。例如:
DataTable TaxView = new DataTable();
DataColumn SalesTaxDetailID = Products.Columns.Add(blah);
应该是,
DataTable TaxView = new DataTable();
DataColumn SalesTaxDetailID = TaxView.Columns.Add(blah);
也:考虑使用常规类而不是DATABATION/P>
仔细查看-您将税列定义添加到产品表中。将它们添加到税表中。例如:
DataTable TaxView = new DataTable();
DataColumn SalesTaxDetailID = Products.Columns.Add(blah);
应该是,
DataTable TaxView = new DataTable();
DataColumn SalesTaxDetailID = TaxView.Columns.Add(blah);
也:考虑使用常规类而不是DATABATE
对不起,我没有注意到。谢谢帮助。对不起,我没有注意到。谢谢帮助。