Can';t使用SqlDataReader和ExecuteReader将SQL中的varbinary放入C#程序中的字节[]

Can';t使用SqlDataReader和ExecuteReader将SQL中的varbinary放入C#程序中的字节[],c#,sql,bytearray,blob,varbinary,C#,Sql,Bytearray,Blob,Varbinary,我见过很多解决这个问题的方法,人们只使用Command.ExecuteScalar作为byte[]

我见过很多解决这个问题的方法,人们只使用
Command.ExecuteScalar作为byte[]
这是我的密码:

public void MNAdapter()
    {
        IsoStorage retVal = new IsoStorage();

        SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
        csb.DataSource = @"LocalMachine\SQLDEV";
        csb.InitialCatalog = "Support";
        csb.IntegratedSecurity = true;
        string connString = csb.ToString();

        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open();

            SqlCommand command = conn.CreateCommand();
            command.CommandText = @"SELECT S.Settings
from Support.dbo.SavedLocalSettings S
inner join WebCatalog.Published.People P
on P.PKey = S.PeopleLink
inner join WebCatalog.Published.Company C
on P.Link = C.PeopleList
where S.DateSaved >= GETDATE()-34
and C.PKey != '530F4622-C30D-DD11-A23A-00304834A8C9'
and C.PKey != '7BAF7229-9249-449E-BEA5-4B366D7ECCD1'
and C.PKey != 'CCBB2140-C30D-DD11-A23A-00304834A8C9'
and S.CompanyName not like 'Tech Support%'
Group By S.PeopleLink, S.Settings";

using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess))
                {
                    //DataTable dt = new DataTable();
                    //dt.Load(reader);

                    byte[] blob = null;
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Binder = new CustomBinder();
                    while (reader.Read())
                    {
                        reader.GetBytes(0,0,blob,0,100000);
                        Console.WriteLine(blob.ToString());
                        retVal = bf.Deserialize(new MemoryStream(blob)) as IsoStorage;
                    }
                }
            }
        }
我还试着先把它们放在数据表中,尽管我认为这是多余的,但它们会作为整数读入

我没有收到任何错误,数据将进入数据读取器,但它就像
reader.GetBytes(0,0,blob,0100000)甚至没有运行,因为blob保持为空

为什么不使用:

blob = (byte[])reader.Items["Settings"];

GetBytes(0,0,blob,0100000); 您希望此方法为您创建字节数组。它不会-它需要一个对现有数组的引用。你必须自己准备阵列

blob = (byte[])reader["Settings"];