All, I have an SQL Parser and editor which I intend to integrate in my application. When I run the following query
select * from sys.sysprocesses;
one of the columns returned is a type of byte[]. This column happily gets put into a DataTable, however, when I do
bindingSource.DataSource = result.DataTable;
and attempt to display the data in a DataGridView I get the obvious ArgumentException. In this position, what in the best way to change the byte[] to a string for display in the DataTable?
I could loop through the DataTable and do some thing like
foreach(DataColumn col in dataTable.Columns)
if (col.DataType == typeof(byte[]))
foreach (DataRow row in dataTable.Rows)
row[col] = Encoding.ASCII.GetString((byte[])row[col]);
But this will attempt to put a string into a byte[] column, and will not work. I could clone the DataTable then change the type,
DataTable dtCloned = dataTable.Clone();
dtCloned.Columns[0].DataType = typeof(String);
foreach (DataRow row in dataTable.Rows)
dtCloned.ImportRow(row);
but I need a conversion step to convert the byte[] into a hex string. What is the best and preferably most efficent way to achieve what I want?
Thanks for your time.