How can i stored the result into another DataTable example called TotalRevenueByMonthExt with primary key totalcategory? Must Empt the TotalRevenueByMonthExt Datatable the n populate the value. Fieldname for 2 table are the same.
Differences is TotalRevenueByMonth is not a unique DataRow. 1 totalcategory can have different productfamily. Mean The totalcategory can exist once.
micnie2020
Member
306 Points
524 Posts
Re: DataSet .Select and .GroupBy
Apr 26, 2012 03:47 PM|LINK
Hi,
I change to:-
for(int j=0; j<10; j++)
{
foreach (DataRow a in dataSet1.TotalRevenueByMonth.Where(p => p.totalcategory.Equals(j)))
{
this.dataSet1.TotalRevenueByMonth.initial_rcColumn.Expression = "ISNULL(SUM(initial_rc), 0)";
this.dataSet1.TotalRevenueByMonth.annual_rcColumn.Expression = "ISNULL(SUM(annual_rc), 0)";
this.dataSet1.TotalRevenueByMonth.rental_rcColumn.Expression = "ISNULL(SUM(rental_rc), 0)";
this.dataSet1.TotalRevenueByMonth.service_rcColumn.Expression = "ISNULL(SUM(service_rc), 0)";
this.dataSet1.TotalRevenueByMonth.training_rcColumn.Expression = "ISNULL(SUM(training_rc), 0)";
this.dataSet1.TotalRevenueByMonth.cos_rcColumn.Expression = "ISNULL(SUM(cos_rc), 0)";
this.dataSet1.TotalRevenueByMonth.initial_rcCoSColumn.Expression = "ISNULL(SUM(initial_rcCoS), 0)";
this.dataSet1.TotalRevenueByMonth.annual_rcCoSColumn.Expression = "ISNULL(SUM(annual_rcCoS), 0)";
this.dataSet1.TotalRevenueByMonth.rental_rcCoSColumn.Expression = "ISNULL(SUM(rental_rcCoS), 0)";
this.dataSet1.TotalRevenueByMonth.service_rcCoSColumn.Expression = "ISNULL(SUM(service_rcCoS), 0)";
this.dataSet1.TotalRevenueByMonth.training_rcCoSColumn.Expression = "ISNULL(SUM(training_rcCoS), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_initial_rcColumn.Expression = "ISNULL(SUM(ytd_initial_rc), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_annual_rcColumn.Expression = "ISNULL(SUM(ytd_annual_rc), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_rental_rcColumn.Expression = "ISNULL(SUM(ytd_rental_rc), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_service_rcColumn.Expression = "ISNULL(SUM(ytd_service_rc), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_training_rcColumn.Expression = "ISNULL(SUM(ytd_training_rc), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_cos_rcColumn.Expression = "ISNULL(SUM(ytd_cos_rc), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_initial_rcCoSColumn.Expression = "ISNULL(SUM(ytd_initial_rcCoS), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_annual_rcCoSColumn.Expression = "ISNULL(SUM(ytd_annual_rcCoS), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_rental_rcCoSColumn.Expression = "ISNULL(SUM(ytd_rental_rcCoS), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_service_rcCoSColumn.Expression = "ISNULL(SUM(ytd_service_rcCoS), 0)";
this.dataSet1.TotalRevenueByMonth.ytd_training_rcCoSColumn.Expression = "ISNULL(SUM(ytd_training_rcCoS), 0)";
}
}
How can i stored the result into another DataTable example called TotalRevenueByMonthExt with primary key totalcategory? Must Empt the TotalRevenueByMonthExt Datatable the n populate the value. Fieldname for 2 table are the same.
Differences is TotalRevenueByMonth is not a unique DataRow. 1 totalcategory can have different productfamily. Mean The totalcategory can exist once.
Please advise.
Thank you.
gopakumar.r
Participant
959 Points
193 Posts
Re: DataSet .Select and .GroupBy
Apr 27, 2012 10:36 AM|LINK
Very sorry, i couldnt undertand your requirement. Also i see that the variable "a" or type data row in never used in the foreach loop.
Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |
micnie2020
Member
306 Points
524 Posts
Re: DataSet .Select and .GroupBy
Apr 27, 2012 11:16 AM|LINK
Tq Sir for your kind reply.
I finally get the solution by using loops as below:-
dataSet1.TotalRevenueByMonthExt.Rows.Clear();
for(int j=1; j<=10; j++)
{
DataRow row = dataSet1.TotalRevenueByMonthExt.NewRow();
Double initial_rcCos = 0.0;
Double initial_rc = 0.0;
:
:
Double ytd_annual_rc = 0.0;
Double ytd_rental_rc = 0.0;
Double ytd_service_rc = 0.0;
Double ytd_training_rc = 0.0;
Double ytd_gross_rc = 0.0;
Double ytd_cos_rc = 0.0;
Double ytd_net_rc = 0.0;
foreach (DataRow a in dataSet1.TotalRevenueByMonth.Select("totalcategory="+j))
{
initial_rcCos += Convert.ToDouble(a.ItemArray[11] == System.DBNull.Value ? 0.0 : a.ItemArray[11]);
:
:
ytd_gross_rc +=Convert.ToDouble(a.ItemArray[33] == System.DBNull.Value ? 0.0 : a.ItemArray[33]);
ytd_cos_rc +=Convert.ToDouble(a.ItemArray[34] == System.DBNull.Value ? 0.0 : a.ItemArray[34]);
ytd_net_rc +=Convert.ToDouble(a.ItemArray[35] == System.DBNull.Value ? 0.0 : a.ItemArray[35]);
row[0] = a.ItemArray[0];
row[1] = a.ItemArray[1];
row[2] = a.ItemArray[2];
:
:
row[28] = ytd_annual_rc;
row[29] = ytd_rental_rc;
row[30] = ytd_service_rc;
row[31] = ytd_training_rc;
row[32] = ytd_gross_rc;
row[33] = ytd_cos_rc;
row[34] = ytd_net_rc;
row[35] = a.ItemArray[36];
}
dataSet1.TotalRevenueByMonthExt.Rows.Add(row);
}
DataSet1.TotalRevenueByMonthExtRow totalPendingNew = (DataSet1.TotalRevenueByMonthExtRow)dataSet1.TotalRevenueByMonthExt.FindBytotalcategory(Helpers.TotalCategory.PNEWBUSINESS);