How do i multiply each cell from the row?
I am using C#,Asp.net and MS sql to develop my web application.
I have a table with 3 columns
Employeetbl
empid primary key
datefrom
dateto
in gridview i display empid,datefrom,dateto, years.
years is a column in the gridview to display year differenct between the two dates.
now i have an other table called Leavetbl which has leaveid, empid,totalleave
empid is foreign key referencing employeetbl.
now i want to insert totalleave for each employee automatically.
if the year difference is 1, leave=14
if year difference is 2=totalleave=>14+15=29
if year difference is 3=>totalleave=14+15+16=45
if year difference is 4=>totalleave=14+15+16+17=62
if year difference is 5=>totalleave=14+15+16+17+18=80
as year difference goes on, totalleave will be sum of previous years plus the new incremented one
so how can i do this? help me please
Re: How do i multiply each cell from the row?
Something like this:
Code:
foreach (DataRow leaveRow in myDataSet.Tables["Leave"].Rows)
{
var employeeRow = leaveRow.GetParentRow("EmployeeLeave");
leaveRow["TotalLeave"] = GetTotalLeave((int)employeeRow["Years"]);
}
Code:
private int GetTotalLeave(int years)
{
int totalLeave = 0;
for (int i = 0; i < years; i++)
{
totalLeave += 14 + i;
}
return totalLeave;
}