public static List <Breakfast> GetAllBreakfast() { List <Breakfast> allDatas = new List <Breakfast> { }; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = @"SELECT * FROM breakfast;"; MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { int breakfastId = rdr.GetInt32(0); string food = rdr.GetString(1); DateTime stampTimeB = rdr.GetDateTime(2); float sugar = rdr.GetFloat(3); float carb = rdr.GetFloat(4); int user_id = rdr.GetInt32(5); Breakfast newBreakfast = new Breakfast(food, stampTimeB, sugar, carb, user_id, breakfastId); allDatas.Add(newBreakfast); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allDatas); }
public static Breakfast Find(int id) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM breakfast WHERE id = (@searchId);"; MySqlParameter searchId = new MySqlParameter(); searchId.ParameterName = "@searchId"; searchId.Value = id; cmd.Parameters.Add(searchId); var rdr = cmd.ExecuteReader() as MySqlDataReader; int BreakfastId = 0; string food = ""; DateTime stampTime = new DateTime(); float sugar = 0; float carb = 0; int userId = 0; while (rdr.Read()) { BreakfastId = rdr.GetInt32(0); food = rdr.GetString(1); stampTime = rdr.GetDateTime(2); sugar = rdr.GetFloat(3); carb = rdr.GetFloat(4); userId = rdr.GetInt32(5); } Breakfast newBreakfast = new Breakfast(food, stampTime, sugar, carb, userId, BreakfastId); conn.Close(); if (conn != null) { conn.Dispose(); } return(newBreakfast); }
public List <Breakfast> GetBreakfasts() { List <Breakfast> allLoginBreakfasts = new List <Breakfast> { }; MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM breakfast WHERE user_id = @user_id;"; MySqlParameter userId = new MySqlParameter(); userId.ParameterName = "@user_id"; userId.Value = this._id; cmd.Parameters.Add(userId); var rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int breakfastId = rdr.GetInt32(0); string food = rdr.GetString(1); DateTime stampTime = rdr.GetDateTime(2); float sugar = rdr.GetFloat(3); float carb = rdr.GetFloat(4); int user_id = rdr.GetInt32(5); Breakfast newBreakfast = new Breakfast(food, stampTime, sugar, carb, user_id); allLoginBreakfasts.Add(newBreakfast); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allLoginBreakfasts); }