如何发现DataColumn的基础数据类型是xml

时间:2020-12-15 15:42:03

I have a SQL Server data table that has an xml column. I run a select query using DataTable (Fill method of the SqlDataAdapter class). After execution, the type of the column is string.

我有一个SQL Server数据表,其中包含一个xml列。我使用DataTable(SqlDataAdapter类的Fill方法)运行select查询。执行后,列的类型是字符串。

I am wondering how I could determine the actual SQL Server datatype (in this case xml) from the DataTable materialized by the Fill method.

我想知道如何从Fill方法实现的DataTable中确定实际的SQL Server数据类型(在本例中为xml)。

I cannot use SqlDataReader (which has GetSchemaTable method that returns the SQL Server datatype information) - I have to use SqlDataAdapter/DataTable. Doing something like:

我不能使用SqlDataReader(它具有返回SQL Server数据类型信息的GetSchemaTable方法) - 我必须使用SqlDataAdapter / DataTable。做类似的事情:

DataTableReader reader = new DataTableReader(table);
DataTable schemaTable = reader.GetSchemaTable();

is also not helpful since it also does not seem to contain the SQL Server datatype information.

也没有帮助,因为它似乎也不包含SQL Server数据类型信息。

1 个解决方案

#1


3  

There is a property on the SqlDataAdapter called ReturnProviderSpecificTypes and if you set this true, then GetSchemaTable() should tell you the column is typeof(SqlXml) rather than typeof(string)

在SqlDataAdapter上有一个名为ReturnProviderSpecificTypes的属性,如果你设置为true,那么GetSchemaTable()应该告诉你该列是typeof(SqlXml)而不是typeof(string)

#1


3  

There is a property on the SqlDataAdapter called ReturnProviderSpecificTypes and if you set this true, then GetSchemaTable() should tell you the column is typeof(SqlXml) rather than typeof(string)

在SqlDataAdapter上有一个名为ReturnProviderSpecificTypes的属性,如果你设置为true,那么GetSchemaTable()应该告诉你该列是typeof(SqlXml)而不是typeof(string)