I have 3 tables created using SQL server:
AMREADING - - Will store AM reading,Date,Timestamp
PMREADING - Will store PM reading,Date,Timestamp
DAILYREADINGS - This will store yesterdays AM,PM & Todays AM reading along with dates and timestamps. It will also store the water usage totals.
I am using entity frameworks, so far I have figured out how to insert/delete a record in the tables. However I need to retrieve a record from the AMREADING table & PMREADING table so I can store in variables and then insert into DAILYREADINGSTABLE. From this I can work out how much water was used : night,day and the total water used.
I have read that I need to create a list which I have done below,
public List<GLOBALVARIABLES> GetData(DateTime usedate) { using (Water.WaterEntities1 context = new Water.WaterEntities1()) { var items = context.amreadings .Where(a => a.datetaken == usedate) .Select(row => new GLOBALVARIABLES { YDAYAMREADING = row.reading, YDAYTIME = row.timestamp, YDAYDATETAKEN = row.datetaken }); return items.ToList<GLOBALVARIABLES>(); }
I also have a global variables class :
public class GLOBALVARIABLES { public static int thisreading; public static DateTime todaysdate = DateTime.Now.Date; public static string thistime = DateTime.Now.ToShortTimeString(); public static int closeform = 0; public Int32 YDAYAMREADING { get; set; } public DateTime YDAYDATETAKEN { get; set; } public string YDAYTIME { get; set; } } }
I just dont know how to access the data?
Any help is much appreciated.