Under the namespace System.Data.SqlClient
, we have both SqlDataReader.GetSqlBinary
and SqlDataReader.GetSqlBytes.
Both seems to give "raw data". If so, what's the difference between them?
As explained earlier, the SqlDataReader returns data via a sequential stream. To read this data, you must pull data from a table row-by-row Once a row has been read, the previous row is no longer available.
It is used to populate an array of objects with the column values of the current row. It is used to get the next result, when reading the results of SQL statements. It is used to read record from the SQL Server database. To create a SqlDataReader instance, we must call the ExecuteReader method of the SqlCommand object.
After creating an instance of the Command object, you create a DataReader by calling Command. ExecuteReader to retrieve rows from a data source, as shown in the following example. SqlDataReader myReader = myCommand. ExecuteReader();
The GetSQLBytes are stored in an inside buffer for more manipulation, the Binary are just a stream that you get and use it as it is.
This two return SqlBytes and SqlBinary and by see this two types you can see the full different of them 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
GetSqlBinary
returns an SqlBinary
structure:
Represents a variable-length stream of binary data to be stored in or retrieved from a database.
GetSqlBytes
returns an SqlBytes
class:
Represents a mutable reference type that wraps either a Buffer or a Stream.
So is seems that the difference is that GetSqlBinary
gives you a lump of data as a byte array, while GetSqlBytes
is similar but stores the data in a buffer which allows you to interact with the underlying data as a stream.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With