C# 使用MySQL数据填充Datagrid操作数据

C# 使用MySQL数据填充Datagrid操作数据,c#,mysql,wpf,datatable,datagrid,C#,Mysql,Wpf,Datatable,Datagrid,我有一个DataGrid,它填充来自MySQL数据库的数据。 我的问题是,数据库中有VarBinary,我需要在DataGrid中显示为字符串。 在一个单独的文本框中,我可以转换字符串中的VarBinary。但是,当它从数据库中读取并将字符串(而不是字节数组)作为字符串放入DataGrid时,我如何转换它呢? 我试过这个: MySqlCommand command = new MySqlCommand(this.queryString, connection);

我有一个DataGrid,它填充来自MySQL数据库的数据。 我的问题是,数据库中有VarBinary,我需要在DataGrid中显示为字符串。 在一个单独的文本框中,我可以转换字符串中的VarBinary。但是,当它从数据库中读取并将字符串(而不是字节数组)作为字符串放入DataGrid时,我如何转换它呢? 我试过这个:

                MySqlCommand command = new MySqlCommand(this.queryString, connection);

                MySqlDataReader reader = command.ExecuteReader();

                DataTable actualldata = new DataTable();

                int i = 0;
                while (reader.Read())
                {
                    //that works to convert the string too but its non-sense with the crash and no save
                    string test;
                    if (reader[i].GetType() == typeof(byte))
                        test = reader.GetString(0);
                    i++;
                }



                if (reader.HasRows)
                {
                    actualldata.Load(reader);
                }
但是在3号之后。循环,它崩溃了,它去我的捕捉块。在没有while循环的情况下,它工作并在DataGrid中显示数据,但使用System.Byte[]。有了它,它崩溃了

查询从表中获取所有数据,而不仅仅是一行

this.queryString = $"SELECT * FROM {tablename};";
我可以使用以下方法转换Var二进制文件:

string encodedByteArray = Encoding.ASCII.GetString(binaryData);
在DataGrid中转换并在DataGrid中显示为字符串的最佳方式是什么?可能吗

DataGrid在后面创建列和绑定代码,因为我可以通过单击按钮切换数据库中的表

TL:DR:我需要在DataTable中操作一个VarBinary值,以便在DataGrid中将其显示为字符串