I'm running with version 6.0.0.300 of the above and connecting to a DB2 Server on Windows Version 11.5. The following code shows the problem:
using IBM.Data.Db2;
using System.Data;
var con = new DB2Connection("your connection string");
con.Open();
var dt = new DataTable("input");
dt.Columns.Add("INPUT_COL", typeof(byte));
dt.Rows.Add(6);
var copy = new DB2BulkCopy(con);
copy.DestinationTableName = "Table Name";
copy.ColumnMappings.Add("INPUT_COL", "NUMBER_COL");
copy.WriteToServer(dt);
con.Close();
This will throw an exception: System.InvalidCastException: 'Unable to cast object of type 'System.Byte' to type 'System.Byte[]'.'
However, if I simply change the
dt.Columns.Add("INPUT_COL", typeof(byte));
Line to:
dt.Columns.Add("INPUT_COL", typeof(short));
Then it works as expected. My application (which supports multiple databases), however, allows users to select any data type including byte as a column type. The underlying Table has a single column of type SMALLINT.
------------------------------
Colin Paterson
------------------------------