Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Task - Reading Tables using MySqlDataAdapter | Optimizing Database Operations
course content

Зміст курсу

Introduction to .NET with C#

Task - Reading Tables using MySqlDataAdapterTask - Reading Tables using MySqlDataAdapter

We are working on the employees table from the last task. You have a program given below that reads some columns from a table. It uses the MySqlDataReader object to read and display the data. Your task is to read and display the exact same data using MySqlDataAdapter instead.

In your solution, while reading the data, the "Salary" column has to be converted to the decimal data type in C#. The decimal data type can store decimal numbers of higher precision than both float and double. It is suitable for representing financial and monetary values and calculations.

This task doesn't have test cases. If you successfully manage to output the correct data using the DataAdapter then it means your solution is correct. You can also verify the correctness of your solution by comparing it with the solution given below.

You also need to create a DataSet object to store the retrieved data.

using System;
using System.Data;
using System.Reflection.PortableExecutable;
using MySql.Data.MySqlClient;

class Program
{
    static void Main(string[] args)
    {
        string connectionString = "host=your_host;port=your_port;user=your_user;password=your_pwd;database=your_db";

        using (MySqlConnection connection = new MySqlConnection(connectionString))
        {
            connection.Open();

			// Change code below this line
			MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM Employees;", connection);
			DataSet dataset = new DataSet();
			adapter.Fill(dataset);

			DataTable table = dataset.Tables[0];
            foreach(DataRow row in table.Rows)
			{
                int id = (int) row["EmployeeID"];
                string firstName = (string) row["FirstName"];
                string lastName = (string) row["LastName"];
                int age = (int) row["Age"];
                string gender = (string) row["Gender"];
                string department = (string) row["Department"];
                string position = (string) row["Position"];
                decimal salary = (decimal) row["Salary"];

                Console.WriteLine($"{id}, {firstName} {lastName}, {age}, {gender}, {department}, {position}, {salary}");
            }
			// Change code above this line
        }
    }
}

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

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

Зміст курсу

Introduction to .NET with C#

Task - Reading Tables using MySqlDataAdapterTask - Reading Tables using MySqlDataAdapter

We are working on the employees table from the last task. You have a program given below that reads some columns from a table. It uses the MySqlDataReader object to read and display the data. Your task is to read and display the exact same data using MySqlDataAdapter instead.

In your solution, while reading the data, the "Salary" column has to be converted to the decimal data type in C#. The decimal data type can store decimal numbers of higher precision than both float and double. It is suitable for representing financial and monetary values and calculations.

This task doesn't have test cases. If you successfully manage to output the correct data using the DataAdapter then it means your solution is correct. You can also verify the correctness of your solution by comparing it with the solution given below.

You also need to create a DataSet object to store the retrieved data.

using System;
using System.Data;
using System.Reflection.PortableExecutable;
using MySql.Data.MySqlClient;

class Program
{
    static void Main(string[] args)
    {
        string connectionString = "host=your_host;port=your_port;user=your_user;password=your_pwd;database=your_db";

        using (MySqlConnection connection = new MySqlConnection(connectionString))
        {
            connection.Open();

			// Change code below this line
			MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM Employees;", connection);
			DataSet dataset = new DataSet();
			adapter.Fill(dataset);

			DataTable table = dataset.Tables[0];
            foreach(DataRow row in table.Rows)
			{
                int id = (int) row["EmployeeID"];
                string firstName = (string) row["FirstName"];
                string lastName = (string) row["LastName"];
                int age = (int) row["Age"];
                string gender = (string) row["Gender"];
                string department = (string) row["Department"];
                string position = (string) row["Position"];
                decimal salary = (decimal) row["Salary"];

                Console.WriteLine($"{id}, {firstName} {lastName}, {age}, {gender}, {department}, {position}, {salary}");
            }
			// Change code above this line
        }
    }
}

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

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