private void UploadToDatabase(HRM hrm, string userComment, string sport) { //The string with the info to the db. string userName = File.ReadAllLines("C:/Users/Public/HeartRateApp/user_data.txt")[0].Split('=')[1]; string connectionString = "Server=127.0.0.1;Port=3306;Database=mydb;Uid=root;password=root"; MySqlConnection connection = new MySqlConnection(connectionString); MySqlCommand command = connection.CreateCommand(); command.CommandText = "INSERT INTO training_sessions(sport, date, start_time, length, meassure_interval, maxhr, resthr, vo2max, weight, runningindex, user_comment, hr_values, username) VALUES(@sport, @date, @start_time, @length, @meassure_interval, @maxhr, @resthr, @vo2max, @weight, @runningindex, @user_comment, @hr_values, @username);"; command.Parameters.AddWithValue("@sport", sport); command.Parameters.AddWithValue("@date", hrm.GetDate()); command.Parameters.AddWithValue("@start_time", hrm.GetStartTime()); command.Parameters.AddWithValue("@length", hrm.GetLength()); command.Parameters.AddWithValue("@meassure_interval", hrm.GetInterval()); command.Parameters.AddWithValue("@maxhr", hrm.GetMaxHR()); command.Parameters.AddWithValue("@resthr", hrm.GetRestHR()); command.Parameters.AddWithValue("@vo2max", hrm.GetVO2Max()); command.Parameters.AddWithValue("@weight", hrm.GetWeight()); command.Parameters.AddWithValue("@runningindex", hrm.GetRunningIndex()); command.Parameters.AddWithValue("@user_comment", userComment); command.Parameters.AddWithValue("@hr_values", hrm.GetHRValues()); command.Parameters.AddWithValue("@username", userName); try { connection.Open(); command.ExecuteNonQuery(); connection.Close(); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine(ex); } }
public void UploadHrmToDatabase(string path, string userComment, string sport) { HRM hrmFile = ReadHRMFile(path); UploadToDatabase(hrmFile, userComment, sport); }