To return multiple rows with sql Server byte array

Asked

Viewed 340 times

1

I need to perform a query, in a table, where the data is of the type varbinary(max), then created the method below:

public List<byte[]> preenche_fotos(string nCrm)
    {
        consql.bd_string();
        SqlConnection sqlconn = new SqlConnection(consql.sqlconn);

        List<byte[]> list_foto = new List<byte[]>();

        try
        {
            consql._sql = @"SELECT bfoto
                            FROM crm_fotos
                            WHERE ncrm = @nCrm";

            SqlCommand cmd = new SqlCommand(consql._sql, sqlconn);

            cmd.Parameters.Add("@nCrm", SqlDbType.VarChar).Value = nCrm;

            sqlconn.Open();

            SqlDataReader leitor = cmd.ExecuteReader();

            while (leitor.Read())
            {
                list_foto.Add(???????);
            }
        }
        catch (Exception error)
        {
            MessageBox.Show("Error" + error);
        }
        finally
        {
            sqlconn.Close();
        }

        return list_foto;
    } 
}

So with the method Read of DataReader, I’ll read the query line by line, but how do I add the value to the list_foto?

  • The solution worked out?

  • 1

    Perfect friend, thank you very much.

1 answer

2


Browser other questions tagged

You are not signed in. Login or sign up in order to post.