SqlDataReader.GetSqlBinary vs SqlDataReader.GetSqlBytes?

In the System.Data.SqlClient namespace, we have SqlDataReader.GetSqlBinary and SqlDataReader.GetSqlBytes .

Both seem to give "raw data." If so, what is the difference between the two?

+6
source share
2 answers

GetSQLBytes are stored in an internal buffer for greater manipulation, Binary is just the stream you receive, and use it as it is.

These two return SqlBytes and SqlBinary, and when you see these two types, you can see them completely and how they store the data.

http://msdn.microsoft.com/en-us/library/system.data.sqltypes.sqlbytes.storage.aspx

http://msdn.microsoft.com/en-us/library/system.data.sqltypes.sqlbytes.aspx

+1
source

GetSqlBinary returns a SqlBinary structure

Represents a variable-length binary data stream that must be stored or retrieved from a database.

GetSqlBytes returns the SqlBytes class

Represents a mutable reference type that wraps either a buffer or a stream.

It seems that the difference is that GetSqlBinary gives you a piece of data as a byte array, while GetSqlBytes is similar, but it saves the data in a buffer that allows you to interact with the underlying data as a stream.

+1
source

Source: https://habr.com/ru/post/893261/


All Articles