How to get the SqlType of a column in a DataTable?

前端 未结 7 454
予麋鹿
予麋鹿 2020-12-31 01:45

I have a DataTable obtained from a SQL DataBase, like this:

using (SqlCommand cmd = new SqlCommand(query, _sqlserverDB))
{
    using (SqlDataAdapter adapter          


        
7条回答
  •  南方客
    南方客 (楼主)
    2020-12-31 02:01

    You cannot because System.Data.DataTable (or DataColumn, or DataSet, or DataRow...) is a generic .NET data container which works the same way regardless on the specific database engine you loaded your data from.

    this means that provided you used a .NET Connector for SQL Server, MySQL, Access, PostgreSQL or anything else, the DataTable and DataColumn classes are always the same and being ADO.NET objects are generic to work with any db engine, so the columns are typed with the .NET types as you have found out.

提交回复
热议问题