I've been successfully using the following code to load data from an ODBC connection into a C#
DataTable
for some time without issues:
public static DataTable ExecuteSqlSelect(string sql, string connectionString)
{
var result = new DataTable();
using (var connection = new OdbcConnection(connectionString))
{
connection.Open();
var command = connection.CreateCommand();
command.CommandText = sql;
var dbReader = command.ExecuteReader();
result.Load(dbReader);
connection.Close();
}
return result;
}
However, I now have a MySql
table with a column of type JSON
. When I try to load data from that table with that method, I get the following error:
Unknown SQL type - 0.
I assume this is because the JSON
type is not recognized by C#'s DataTable
. Is this correct? And more importantly: is there a solution/workaround for this?
EDIT: I'm not trying to convert a JSON string to a DataTable, as a commenter suggested... I'm trying to load a SQL table that contains a columns of MySQL type 'JSON' into a DataTable. I don't need JSON parsing, it would be fine if I just got the raw JSON string into the DataTable.
EDIT 2: both MySql and the ODBC connector are the latest version: 8.0.11