C# : Display result  from array in a gridview

NerishaB
NerishaB used Ask the Experts™
on
Hi,

I have created a query to a SQL database, and put the results of my table in an array.  Now, I want to perform calculations based on the data in the array, and display the results in a gridview, so that I may see what the result looks like  Can anyone help me do this?

My code is below:
string[,] HrsWorkedTable = new string[qry.TotalRows, 24];
for (qryRows = 0; qryRows < qry.TotalRows; qryRows++)
  {
      double HoursWorkedDuringBreak = 0.00;
      DateTime ClockInOutTime = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990, 5, 6)).ConvertFrom(qry.Item(qryRows, 8).FieldValue));
      DateTime DefShiftStartTime = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990, 5, 6)).ConvertFrom(qry.Item(qryRows, 4).FieldValue));
      DateTime DefShiftEndTime = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990, 5, 6)).ConvertFrom(qry.Item(qryRows, 5).FieldValue));
      DateTime BreakStart = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990, 5, 6)).ConvertFrom(qry.Item(qryRows, 21).FieldValue));
      DateTime BreakEnd = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990, 5, 6)).ConvertFrom(qry.Item(qryRows, 22).FieldValue));

if ((ClockInOutTime.TimeOfDay < DefShiftStartTime.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "IN"))
       {
         DateTime ClockIn = ClockInOutTime;
         TimeSpan ResultBeforeShift = DefShiftStartTime.TimeOfDay - ClockInOutTime.TimeOfDay;
         double WorkHoursBeforeShift = ResultBeforeShift.TotalSeconds / 60.0;
        }
        else if ((ClockInOutTime.TimeOfDay > DefShiftStartTime.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "IN"))
        {
                    DateTime ClockIn = ClockInOutTime;
                    TimeSpan ResultLateStart = ClockInOutTime.TimeOfDay - DefShiftStartTime.TimeOfDay;
                    double HoursWorkedLateStart = ResultLateStart.TotalSeconds / 60.0;
                }

                if ((ClockInOutTime.TimeOfDay < BreakStart.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "OUT"))
                {
                    DateTime ClockOutBreak = ClockInOutTime;
                    TimeSpan ResultEarlyBreak = BreakStart.TimeOfDay - ClockInOutTime.TimeOfDay;
                    double HoursEarlyBreak = ResultEarlyBreak.TotalSeconds / 60.0;
                }
                else if ((ClockInOutTime.TimeOfDay > BreakStart.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "OUT"))
                {
                    DateTime ClockOutBreak = ClockInOutTime;
                    TimeSpan ResultWorkBreak = ClockInOutTime.TimeOfDay - BreakStart.TimeOfDay;
                    HoursWorkedDuringBreak = ResultWorkBreak.TotalSeconds / 60.0;
                }

                if ((ClockInOutTime.TimeOfDay < BreakEnd.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "IN"))
                {
                    DateTime ClockInEarlyBreak = ClockInOutTime;
                    TimeSpan ResultEndBreakEarly = BreakEnd.TimeOfDay - ClockInOutTime.TimeOfDay;
                    HoursWorkedDuringBreak += (ResultEndBreakEarly.TotalSeconds / 60.0);
                }
                else if ((ClockInOutTime.TimeOfDay > BreakEnd.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "IN"))
                {
                    DateTime ClockInAfterBreak = ClockInOutTime;
                    TimeSpan ResultAfterBreak = ClockInOutTime.TimeOfDay - BreakEnd.TimeOfDay;
                    double ExtraBreakTime = ResultAfterBreak.TotalSeconds / 60.0;
                }

                if ((ClockInOutTime.TimeOfDay <= DefShiftEndTime.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "OUT"))
                {
                    DateTime ClockOutEndOfDay = ClockInOutTime;
                    TimeSpan ResultEarlyLeave = DefShiftEndTime.TimeOfDay - ClockInOutTime.TimeOfDay;
                    double TimeLeftEarly = ResultEarlyLeave.TotalSeconds / 60.0;
                }
                else if ((ClockInOutTime.TimeOfDay >= DefShiftEndTime.TimeOfDay) && (qry.Item(qryRows, 9).FieldValue.ToString() == "OUT"))
                {
                    DateTime ClockOutAfterShiftEnd = ClockInOutTime;
                    TimeSpan ResultAfterShift = ClockInOutTime.TimeOfDay - DefShiftEndTime.TimeOfDay;
                    double HoursWorkedAfterShift = ResultAfterShift.TotalSeconds / 60.0;
                }
            }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
.Net Full Stack Developer
Commented:
Hi!

How about creating the Table
and as you loop through add Row to that Table
coolumn would be the Values you need to Check in Table

And at  the End you get your Table and Bind to GridView

Thanks!

Author

Commented:
Can you please give me an example on how to do this?  I am very new to this.

Author

Commented:
I am closing the question as no other responses arrived.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial