0

Current, converting c# BitArray to byte[] then save to SQL Server. Is there any way to save it directly?

var byteArray = new byte[625];
bitArray.CopyTo(byteArray, 0);
Save(byteArray);

As reading from Binary to BitArray, using byte[] to receive the value and then converting to BitArray. Any way direct?

2
  • 1
    SQL Server stores Bit arrays packed as 8 bytes which is a byte array. You may just need to cast from one type to the other. Commented Apr 10, 2023 at 9:46
  • 1
    SQL Server 2022 (and Azure SQL Database) now also support various bit manipulation functions which work on the non-LOB binary type as well. So, you can get and set bits, shift bit values, and count set bits in the SQL layer as needed. Like jdweng says, you just cast in/out when converting from an app-tier concept like a bit array. SQL does not have an array type as such. Commented Apr 10, 2023 at 12:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.