MySqlCommand cmd = new MySqlCommand("SELECT image FROM products WHERE id = @id", conn); cmd.Parameters.AddWithValue("@id", 123); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { byte[] buffer = new byte[4096]; long bytesReceived = 0; int offset = 0; int startIndex = 0; int count = 4096; while ((bytesReceived = reader.GetBytes(startIndex, offset, buffer, startIndex, count)) > 0) { offset += (int)bytesReceived; } }
using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM myTable", myConnection)) using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { byte[] buffer = new byte[1024]; int bytesRead = reader.GetBytes(0, 0, buffer, 0, 1024); // Process the data... } }In this example, we retrieve all rows from the myTable table in a MySQL database using a MySqlCommand and a MySqlDataReader. We then read data from the first column in each row using GetBytes method and process the data. These examples are part of the MySql.Data.dll package library.