Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Task - Using SELECT | CRUD Operations with MySQL
Introduction to .NET with C#

Task - Using SELECTTask - Using SELECT

The store owner wants to retrieve a list of all the products that are under 100 in terms of quantity so that they can order more stock in advance.

Your task is to retrieve and display all the products from the store table where the quantity is less than 100. You have to retrieve all the columns from the selected products. You need to display each row in the following format:

Link to the Task: GitHub
This time it is a query, so you will use the ExecuteReader() method for executing the SELECT statement.

using MySql.Data.MySqlClient;

public class CRUD_Task_3
{
    public static void Main(string[] args)
    {
        // Modify connection string here 
        string connectionString = "server=localhost;port=7777;user=root;password=Th!sIsMyPassword;database=school;";

        // Write & Modify code below this line
        using (MySqlConnection connection = new MySqlConnection(connectionString))
        {
            connection.Open();

            string cmdText = "SELECT * FROM store WHERE stock_quantity < 100;";
            MySqlCommand cmd = new MySqlCommand(cmdText, connection);

            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    int id = reader.GetInt32("id");
                    string name = reader.GetString("name");
                    string category = reader.GetString("category");
                    float price = reader.GetFloat("price");
                    int quantity = reader.GetInt32("stock_quantity");

                    Console.WriteLine($"{id}, {name}, {category}, {price}, {quantity}");
                }
            }
        }
        // Write & Modify code above this line
    }
}
  

Все було зрозуміло?

Секція 4. Розділ 8
course content

Зміст курсу

Introduction to .NET with C#

Task - Using SELECTTask - Using SELECT

The store owner wants to retrieve a list of all the products that are under 100 in terms of quantity so that they can order more stock in advance.

Your task is to retrieve and display all the products from the store table where the quantity is less than 100. You have to retrieve all the columns from the selected products. You need to display each row in the following format:

Link to the Task: GitHub
This time it is a query, so you will use the ExecuteReader() method for executing the SELECT statement.

using MySql.Data.MySqlClient;

public class CRUD_Task_3
{
    public static void Main(string[] args)
    {
        // Modify connection string here 
        string connectionString = "server=localhost;port=7777;user=root;password=Th!sIsMyPassword;database=school;";

        // Write & Modify code below this line
        using (MySqlConnection connection = new MySqlConnection(connectionString))
        {
            connection.Open();

            string cmdText = "SELECT * FROM store WHERE stock_quantity < 100;";
            MySqlCommand cmd = new MySqlCommand(cmdText, connection);

            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    int id = reader.GetInt32("id");
                    string name = reader.GetString("name");
                    string category = reader.GetString("category");
                    float price = reader.GetFloat("price");
                    int quantity = reader.GetInt32("stock_quantity");

                    Console.WriteLine($"{id}, {name}, {category}, {price}, {quantity}");
                }
            }
        }
        // Write & Modify code above this line
    }
}
  

Все було зрозуміло?

Секція 4. Розділ 8
some-alt