title: Retrieve a saved image in byte array using stored procedure in C#
body: <p>I have saved an image as byte array in a SQL Server database table successfully. Now I need to retrieve it using a stored procedure.</p>
  <p>Model:</p>
  <pre><code>public class PlateNumberEntity
  {
      public DateTime EntryDateTime { get; set; }
      public string PlateNumber { get; set; } = string.Empty;
      public string Plaza { get; set; } = string.Empty;
      public string Direction { get; set; } = string.Empty;
      public byte[]? OverViewImage { get; set; } = null;
  }
  </code></pre>
  <p>Repository:</p>
  <pre><code>public List&lt;PlateNumberEntity&gt; GetPlateNumberEntities(string plateNumber)
  {
      var list = new List&lt;PlateNumberEntity&gt;();
  
      using(connection = new SqlConnection(connectionString))
      {
          connection.Open();
  
          using(var cmd = connection.CreateCommand())
          {
              cmd.CommandText = &quot;[dbo].[GetAlprEntryInfo]&quot;;
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.CommandTimeout = 10;
  
              var pPlateNumber = new SqlParameter
              {
                  ParameterName = &quot;@PlateNumber&quot;,
                  DbType = DbType.String,
                  Direction = ParameterDirection.Input,
                  Value = plateNumber
              };
  
              cmd.Parameters.Add(pPlateNumber);
  
              using(var reader = cmd.ExecuteReader())
              {
                  if (reader.HasRows)
                  {
                      while (reader.Read())
                      {
                          var entryDateTime = reader.GetDateTime(0);
                          var plate = reader.GetString(1);
                          var plaza = reader.GetString(2);
                          var direction = reader.GetString(3);
                          var overViewImage = reader.??? ====&gt; HOW TO RETRIEVE THE BYTES
                          
                          var xList = new PlateNumberEntity
                          {
                              ....
                          }
                          list.Add(xList)
                      }
                  }
              }
          }
      }
  
      return list;
  }
  </code></pre>
  <p>I think I can use <code>reader.GetBytes(&lt;parameters&gt;)</code>, but the size of the image may vary.</p>