473,387 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Datatable making columns out of rows

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[i][1].ToString()=="In")
{
dr["PunchTime"]=ds.Tables[0].Rows[i][0];
dgcs.HeaderText = "TimeIn";
}
if(ds.Tables[0].Rows[i][1].ToString()=="Out")
{
dr["PunchTime"]=ds.Tables[0].Rows[i][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
Nov 16 '05 #1
3 1700
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
Nov 16 '05 #2
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
Nov 16 '05 #3
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
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the...
1
by: Job Lot | last post by:
Is it possible to use Aggregate functions with GROUP BY Clauses on DataTable. I have a DataTable with following values: Date Amount Int Balance 1/1/2004 5000.00 50.00 5050.00...
5
by: Stefan Turalski \(stic\) | last post by:
Hi, I'm wondering if there is a way to send a method parametrs by ref when DataTabel is a type of this value ? I done some sort of select over DataTable columns, just by removing them froma...
2
by: ven | last post by:
Hello i have a dynamic datatable in my page. I wanna to write data to textboxes and after click on button "ADD data" i want to refresh datagrid on page... Here is my code : ' Insert page code...
3
by: cortex | last post by:
Hi all, i'm newhere and I'm french so excuse me for my bad english :( In my dataset I have 2 Table: -the first named questionnaire which has 4 columns: question_Id, ennonce, format and type...
3
by: Datatable Dataset Datagrid help | last post by:
Hi I am somewhat confused, I am new at VB.net I use XML data, I have a datagrid, I created a datatable so that I can create a custom format like true is this graphic false is this graphic and...
1
by: Lars E | last post by:
Hi all I have a small problem. I have a datatable with 8 columns. But it is only data in 5 of the columns. Data for the remaing 3 columns is in another dataset. I Want to run trough the...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
11
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.