а как определил, что возвращает null?
вообще приведенный тобой код работает. на всякий случай код, который работает у меня:
m_con.Open();
// write to DB
string strSql = "update [Groups] set [Group Icon] = @icon where [ID] = 3";
SqlCommand cmdUpd = new SqlCommand(strSql, m_con);
cmdUpd.Parameters.Add("@icon", SqlDbType.VarBinary);
using(FileStream fsIn = new FileStream(@"c:\temp\_in.ico", FileMode.Open))
{
byte[] bytes = new byte[fsIn.Length];
fsIn.Read(bytes, 0, (int) fsIn.Length);
cmdUpd.Parameters[0].Value = bytes;
cmdUpd.ExecuteNonQuery();
}
// read from DB
strSql = "select [Group Icon] from [Groups] where [ID] = 3";
SqlCommand cmdSel = new SqlCommand(strSql, m_con);
using(FileStream fsOut = new FileStream(@"c:\temp\_out.ico", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write))
{
byte[] bytes;
using (System.Data.SqlClient.SqlDataReader rd = cmdSel.ExecuteReader())
{
if (rd.Read())
{
bytes = (byte[])rd.GetSqlBinary(0);
fsOut.Write(bytes, 0, bytes.GetLength(0));
}
}
}
m_con.Close();