There is such a method:

Dictionary<string, string> GetColumnsList(OleDbConnection conn, string tableName) { var columns = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new[] { null, null, tableName, null }); return columns.AsEnumerable(). Select(x => new { ColumnName = x.Field<string>("Column_Name"), Description = $"Data_Type:{ x.Field<int>("Data_Type")};"+ $"IsNullable:{ x.Field<bool>("IS_NULLABLE")};"+ $"CharacterMaximumLength: { x.Field<int?>("Character_Maximum_Length")};"+ $"CharacterOctetLength: { x.Field<int?>("Character_Octet_Length")}" }).ToDictionary(key => key.ColumnName, value => value.Description); } 

So, I can not understand why an exception crashes when I try to use an int? .

The columns in DataTable themselves are of type int.

System.InvalidCastException: 'Specified cast is not valid.'

at System.Data.DataRowExtensions.UnboxT 1.NullableField[TElem](Object value) at System.Data.DataRowExtensions.Field[T](DataRow row, String columnName) at AccessToMySql.Classes.AccessReader.<>c.<GetColumnsList>b__5_0(DataRow x) in D:\Projects\AccessToMySql\AccessToMySql\Classes\AccessReader.cs:line 52 at System.Linq.Enumerable.WhereSelectEnumerableIterator 2.MoveNext ()
at System.Linq.Enumerable.ToDictionary [TSource, TKey, TElement] (IEnumerable 1 source, Func IE 1 source, Func 2 keySelector, Func 2 elementSelector, IEqualityComparer 1 comparer) at System.Linq.Enumerable. 1 source, Func 2 keySelector, Func`2 elementSelector) at AccessToMySql.Classes. .ProcessingMdb (String pathToMdb) in D: \ Projects \ AccessToMySql \ AccessToMySql \ Classes \ AccessReader.cs: line 37 at AccessToMySql. line 26 at AccessToMySql.Program.Main (String [] args) in D: \ Projects \ AccessToMySql \ AccessToMySql \ Program.cs: line 17

  • The columns in DataTable themselves are of type int. that is why an exception occurs that you are trying to deploy int32 - Grundy
  • Although not, I checked it with a simple example: everything works as expected, add the full text of the error with stacktrace to the question - Grundy
  • @Grundy added. - iluxa1810
  • Data_Type is hardly an int, is it true? - 4per
  • Hmm ... it looks like Long was needed. Long? works. It was necessary to examine the DataTable in the debugger. - iluxa1810

0