Shaitan00 Posted November 19, 2008 Posted November 19, 2008 This is going to be fun to explain... I have a DATABASE that contains the following data: -DATE--------TIME----LEVEL 19/11/2008 - 8:00am - 05 19/11/2008 - 9:00am - 10 20/11/2008 - 8:00am - 06 20/11/2008 - 9:00am - 11 21/11/2008 - 8:00am - 12 So there is a column for DATE, a column for TIME, and a column for LEVEL. However, I need to display the data in a different format, specifically something like this ------------8:00am--9:00am 19/11/2008 -- 05 --- 10 20/11/2008 -- 06 --- 11 21/11/2008 -- 12 Notice that I have changed the orientation of the data, instead of having a row per Date/Time I now have columns that are TIME and rows that are DAYS and the intersection is the corresponding LEVEL. Is there an easy way to transform the original data from the Database into such a format so I can use somekind of element to display it to the user? Like a gridview or whatever works best? Any help would be greatly appreciated. Thanks, Quote
Nate Bross Posted November 19, 2008 Posted November 19, 2008 Which version of the Framework are you targeting? 2.0, 3.0, 3.5? Is using Linq an option? What dbms are you using? Access, SQL server, MySQL? You need to get all of your records from the database, then get a distinct list of Dates, then for each distinct date, write out the time and level for each record with that date. ex: data = select * from table; distinct = Enumerable.Dinstinct(Data.DATE); foreach(row in (from d in data where d.DATE == distinct select d)) response.write(row.TIME + " " + row.LEVEL); Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Shaitan00 Posted November 20, 2008 Author Posted November 20, 2008 Framework is 3.5 DB = Microsoft SQL Server Express 2005 What is LINQ? Quote
Nate Bross Posted November 20, 2008 Posted November 20, 2008 Linq is Language Integrated Query. It lets you write "SQL-esque" code in C# directly to your objects in memory. (There is also LINQ to SQL which lets you write Linq in C# and it is converted into SQL, and LINQ to XML) http://en.wikipedia.org/wiki/Language_Integrated_Query and http://msdn.microsoft.com/en-us/library/bb308959.aspx are probably both worth a read. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.