I’m trying to write a test that returns a data-reader with one of the columns being a byte[].
I figured I can create a datatable and create a reader from that.
var cboTable = new DataTable("CBOTable");
var colValue = new SqlBinary(ASCII.GetBytes("Hello This is test"));
cboTable.Columns.Add("ByteArrayColumn");
cboTable.Rows.Add(colValue);
var reader= cboTable.CreateDataReader();
the problem is when I add colValue to the datarow instead of adding it as a byte[] it adds it to the row as it’s string representation which is "SqlBinary(18)".
my question is how do I add an actual byte[] to my datarow
According to MSDN:
By writing
cboTable.Columns.Add("ByteArrayColumn");, you’ve defined a column name, but not given it a type, so it defaults to being a “string” column. You should follow the example in the doc in order to create the table schema before adding data to the table.