Exemple #1
0
        /// <summary>
        /// select customer as an asynchronous operation.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <returns>Task&lt;System.String&gt;.</returns>
        public async Task <string> SelectCustomerAsync(int customerId)
        {
            String       sql     = "select * from customer where customer_id = @customer_id";
            AceQLCommand command = new AceQLCommand(sql, connection);

            command.Parameters.AddWithValue("@customer_id", 1);

            String resultString = null;

            using (AceQLDataReader dataReader = await command.ExecuteReaderAsync())
            {
                while (dataReader.Read())
                {
                    int i = 0;
                    resultString  = dataReader.GetString(i++);
                    resultString += " / " + dataReader.GetString(i++);
                    resultString += " / " + dataReader.GetString(i++);
                    resultString += " / " + dataReader.GetString(i++);
                    resultString += " / " + dataReader.GetString(i++);
                    resultString += " / " + dataReader.GetString(i++);
                    resultString += " / " + dataReader.GetString(i++);
                    resultString += " / " + dataReader.GetString(i++);
                }
            }

            return(resultString);
        }
        /// <summary>
        /// Example of 2 SELECT.
        /// </summary>
        /// <param name="customerId">The cutomer ID.</param>
        private async Task SelectCustomerAndOrderLogAsync(int customerId)
        {
            // Display the created Customer:
            string sql = "select customer_id, fname, lname from customer "
                         + " where customer_id = @customer_id";

            AceQLCommand command = new AceQLCommand(sql, connection);

            command.Parameters.AddWithValue("@customer_id", customerId);

            using (AceQLDataReader dataReader = await command.ExecuteReaderAsync())
            {
                while (dataReader.Read())
                {
                    int    i           = 0;
                    int    customerId2 = dataReader.GetInt32(i++);
                    string fname       = dataReader.GetString(i++);
                    string lname       = dataReader.GetString(i++);

                    AceQLConsole.WriteLine();
                    AceQLConsole.WriteLine("customer_id : " + customerId2);
                    AceQLConsole.WriteLine("fname       : " + fname);
                    AceQLConsole.WriteLine("lname       : " + lname);
                }
            }

            sql = "select * from orderlog where customer_id = @customer_id and item_id = @item_id ";

            command = new AceQLCommand(sql, connection);
            command.Parameters.AddWithValue("@customer_id", customerId);
            command.Parameters.AddWithValue("@item_id", customerId);

            using (AceQLDataReader dataReader = await command.ExecuteReaderAsync())
            {
                while (dataReader.Read())
                {
                    int i           = 0;
                    int customerId2 = dataReader.GetInt32(i++);
                    int itemId2     = dataReader.GetInt32(i++);

                    string  description = dataReader.GetString(i++);
                    Decimal costPrice   = dataReader.GetDecimal(i++);

                    DateTime datePlaced  = dataReader.GetDateTime(i++).Date;
                    DateTime dateShipped = dataReader.GetDateTime(i++);

                    Stream stream = await dataReader.GetStreamAsync(i ++); // null stream

                    bool is_delivered = dataReader.GetInt32(i++) == 1 ? true : false;
                    int  quantity     = dataReader.GetInt32(i++);

                    AceQLConsole.WriteLine("customer_id : " + customerId2);
                    AceQLConsole.WriteLine("item_id     : " + itemId2);
                    AceQLConsole.WriteLine("description : " + description);
                    AceQLConsole.WriteLine("cost_price  : " + costPrice);
                    AceQLConsole.WriteLine("date_placed : " + datePlaced.Date);
                    AceQLConsole.WriteLine("date_shipped: " + dateShipped);
                    AceQLConsole.WriteLine("is_delivered: " + is_delivered);
                    AceQLConsole.WriteLine("quantity    : " + quantity);
                }
            }
        }