Example #1
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionString = SqlConnectionUtility.GetSqlConnection();

            optionsBuilder.UseMySQL(connectionString);
            base.OnConfiguring(optionsBuilder);
        }
Example #2
0
        public void InsertNewLocation(LocationWithQueries.Models.Location location)
        {
            string myConnectionString = SqlConnectionUtility.GetSqlConnection();

            try
            {
                var conn = new MySqlConnection();
                conn.ConnectionString = myConnectionString;
                var con = new MySqlConnection(myConnectionString);
                con.Open();

                var insert = Queries.Queries.InsertNewLocation;

                var cmd = new MySqlCommand(insert, con);

                var parameters = PopulateParameters(location);
                cmd.Parameters.Clear();
                cmd.Parameters.AddRange(parameters.ToArray());

                int rowsAffected = cmd.ExecuteNonQuery();
                if (rowsAffected != 1)
                {
                    throw new Exception();
                }
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                // MessageBox.Show(ex.Message);
            }
        }
Example #3
0
        public static void InsertNewLocation(Location location)
        {
            string myConnectionString = SqlConnectionUtility.GetSqlConnection();


            try
            {
                var conn = new MySqlConnection();
                conn.ConnectionString = myConnectionString;
                var con = new MySqlConnection(myConnectionString);
                con.Open();

                //var insert = Queries.InsertNewLocation;

                // var cmd = new MySqlCommand(insert, con);

                //var parameters = PopulateParameters(location);
                //cmd.Parameters.Clear();
                //cmd.Parameters.AddRange(parameters.ToArray());

                //int rowsAffected = cmd.ExecuteNonQuery();
                //if (rowsAffected != 1)
                //{
                //    throw new Exception();
                //}
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }