Results 1 to 2 of 2

Thread: How do i multiply each cell from the row?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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;
    }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width