示例#1
0
        //Little helper method to get the orders
        //To DO - Need to learn Connection Pooling or Entity Framework - this is really inefficient!
        public static List <Order> lookUpOrders()
        {
            var results = new List <Order>();

            try
            {
                MySqlConnection conn = new MySqlConnection(CloudConnectionHelper.connectionString());
                conn.Open();
                string          stm        = "SELECT * FROM orders";
                MySqlCommand    cmd        = new MySqlCommand(stm, conn);
                MySqlDataReader dataReader = cmd.ExecuteReader();
                while (dataReader.Read())
                {
                    Order newOrder = new Order {
                        ID = dataReader.GetInt32(0), customerId = dataReader.GetInt32(1), quantity = dataReader.GetInt32(2)
                    };
                    results.Add(newOrder);
                }
                conn.Close();
                dataReader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.ToString());
            }
            return(results);
        }
示例#2
0
 //Open the DB and any other resources
 private static void obtainDBConnection()
 {
     Console.WriteLine("Openning Connection");
     if (conn == null)
     {
         conn = new MySqlConnection(CloudConnectionHelper.connectionString());
         conn.Open();
     }
     if (cmd == null)
     {
         cmd = conn.CreateCommand();
     }
     Console.WriteLine("Connection Open");
 }