mercredi 18 octobre 2017

System.NotSupportedException: ''DataSet' supports not System.Nullable<>

I am retrieving propertyInfos from a given type.

When a property is of type Nullable then I can not add the property type to the dataTable.columns collection because I get an exception:

System.NotSupportedException: ''DataSet' supports not System.Nullable<>.'

foreach (var prop in propertyInfos)
            {
                if (prop.PropertyType == typeof(int?))
                {

                    dataTable.Columns.Add(prop.Name, prop.PropertyType);
                }
                else
                {
                    dataTable.Columns.Add(prop.Name, prop.PropertyType);

                }
            }

What should I change in the if-clause to make it work?

I already added null or DBNull to the collection but that did not help?!





Aucun commentaire:

Enregistrer un commentaire