I need to read a BLOB and store it in a byte[], before going forward with Deserializing;
Consider:
//Reading the Database with DataAdapterInstance.Fill(DataSet);
DataTable dt = DataSet.Tables[0];
foreach (DataRow row in dt.Rows)
{
byte[] BinDate = Byte.Parse(row["Date"].ToString()); // convert successfully to byte[]
}
I need help in this C# statement, as I am not able to convert an object type into a byte[]. Note, "Date" field in the table is a blob and not of type Date;
Help appreciated; Soham
At first, I have created an object of Scanner class and read my file using FileReader() method. Then created a BLOB object initialized with null. Next, I have Converted the file into a Byte array ( byte[] ), stored it into my_byte_array. Finally converted the byte array into BLOB using SerialBlob() method.
Blob simply means (Binary Large Object) and its the way database stores byte array.
In Sql Server, use image data type or varbinary data type, to store byte array data.
In C#.Net, we can create an unsigned byte array by using byte, byte is used to store only positive values between the range of 0 to 255 (Unsigned 8 bits integer). It occupies 1-byte memory for each element, if array size is 10, it will take 10 bytes memory.
Just cast the value to a byte array:
byte[] binDate = (byte[])row["Date"];
A blob in the database maps to a byte array in .NET, so the database driver have already done that conversion for you.
byte[] binDate = (byte[])row["Date"];
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