public static void ReadFromStream(int FileId, Stream stream) { DbTransaction.Demand(); SqlParameter PointerOutParam = DbHelper2.mp("@Pointer", SqlDbType.VarBinary, 16, null); PointerOutParam.Direction = ParameterDirection.Output; DbHelper2.RunSp("FileUpdateDataPrepare", DbHelper2.mp("@FileId", SqlDbType.Int, FileId), DbHelper2.mp("@Size", SqlDbType.Int, System.Convert.ToInt32(stream.Length)), PointerOutParam); // Set up UPDATETEXT command, parameters, and open BinaryReader. SqlParameter PointerParam = DbHelper2.mp("@Pointer", SqlDbType.Binary, 16, null); SqlParameter OffsetParam = DbHelper2.mp("@Offset", SqlDbType.Int, null); SqlParameter DeleteParam = DbHelper2.mp("@Delete", SqlDbType.Int, 1); SqlParameter BytesParam = DbHelper2.mp("@Bytes", SqlDbType.Image, null); System.IO.BinaryReader br = new System.IO.BinaryReader(stream); int Offset = 0; OffsetParam.Value = Offset; SqlCommand cmd = null; // Read buffer full of data and execute UPDATETEXT statement. Byte [] Buffer = br.ReadBytes(iBufferSize); while (Buffer.Length > 0) { PointerParam.Value = PointerOutParam.Value; BytesParam.Value = Buffer; cmd = DbHelper2.RunSp(cmd, "FileUpdateData", PointerParam, OffsetParam, DeleteParam, BytesParam); DeleteParam.Value = 0; //Do not delete any other data. Offset += Buffer.Length; OffsetParam.Value = Offset; Buffer = br.ReadBytes(iBufferSize); } br.Close(); }