Datatable making columns out of rows

R

Rajeev

I am writing an Attendance Management system in C#.NET. The data which
comes from the table looks like this:

PunchTime PunchType
5/13/2004 9:00:00 In
5/13/2004 9:15:00 Out
5/13/2004 10:00:34 In
5/13/2004 11:08:00 Out

I can never be sure how many times a person will punch in or out in a
day.

I am using a for loop to get to show this data using a datatable. I
need to know how can i create a new column based on new row and based
of if it is in or out i would like to show something like this for the
data shown above:

TimeIn TimeOut TimeIn TimeOut
9:00:00 9:15:00 10:00:34 11:08:00

Here is small part of the code that I am using:
timeSheet.TableStyles.Clear();
System.Data.DataTable dataTable1 = new
System.Data.DataTable("DataTable1");
dataTable1.Columns.Add("PunchTime").DataType =
System.Type.GetType("System.String");
System.Data.DataRow dr;
DataColumn dc=new DataColumn();
System.Windows.Forms.DataGridTableStyle dgts = new
System.Windows.Forms.DataGridTableStyle();
System.Windows.Forms.DataGridColumnStyle dgcs = new
System.Windows.Forms.DataGridTextBoxColumn();

dr = dataTable1.NewRow();

for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
if(ds.Tables[0].Rows[1].ToString()=="In")
{
dr["PunchTime"]=ds.Tables[0].Rows[0];
dgcs.HeaderText = "TimeIn";
}
if(ds.Tables[0].Rows[1].ToString()=="Out")
{
dr["PunchTime"]=ds.Tables[0].Rows[0];
dgcs.HeaderText = "TimeOut";
}
};

dataTable1.Rows.Add(dr);

dgcs.MappingName = "PunchTime";
dgcs.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
dgcs.Width = 100;
dgts.GridColumnStyles.Add(dgcs);

Thanks
 
R

Rajeev

The problem is I can create a new row. But I would like to create a
new column based on a new row. Any help will be appreciated.

Thanks
 
R

Rajeev

The problem is I can create a new row. But I would like to create a
new column based on a new row. Any help will be appreciated.

Thanks
 
R

Rajeev

The problem is I can create a new row. But I would like to create a
new column based on a new row. Any suggestions will be appreciated.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top