DataSet does not support System.Nullable<>
-
Hi, I've a function tht converts IEnumerable To DataTable, my problem is that one off the columns allowes Nullable and then i get this exception- DataSet does not support System.Nullable <> here is part of my function-
foreach (PropertyInfo pi in pis) { if (dt.Columns.Count == 0) { foreach (PropertyInfo pi in pis) { dt.Columns.Add(pi.Name, pi.PropertyType); } }
i tried to change the function to-if (dt.Columns.Count == 0) { foreach (PropertyInfo pi in pis) { Type propType = pi.PropertyType; if (propType.IsGenericType && propType. == typeof(System.Nullable)) { propType = Nullable.GetUnderlyingType(propType); } dt.Columns.Add(pi.Name, pi.PropertyType); } }
but i'm still getting the exception: :doh: + pi {System.Nullable`1[System.DateTime] "myColumnName"} System.Reflection.PropertyInfo {System.Reflection.RuntimePropertyInfo} What i'm doing wrong? -
Hi, I've a function tht converts IEnumerable To DataTable, my problem is that one off the columns allowes Nullable and then i get this exception- DataSet does not support System.Nullable <> here is part of my function-
foreach (PropertyInfo pi in pis) { if (dt.Columns.Count == 0) { foreach (PropertyInfo pi in pis) { dt.Columns.Add(pi.Name, pi.PropertyType); } }
i tried to change the function to-if (dt.Columns.Count == 0) { foreach (PropertyInfo pi in pis) { Type propType = pi.PropertyType; if (propType.IsGenericType && propType. == typeof(System.Nullable)) { propType = Nullable.GetUnderlyingType(propType); } dt.Columns.Add(pi.Name, pi.PropertyType); } }
but i'm still getting the exception: :doh: + pi {System.Nullable`1[System.DateTime] "myColumnName"} System.Reflection.PropertyInfo {System.Reflection.RuntimePropertyInfo} What i'm doing wrong?treuveni wrote:
What i'm doing wrong? ... dt.Columns.Add(pi.Name, pi.PropertyType);
Guess you wanted to use
propType
instead ofpi.PropertyType
? -
Hi, I've a function tht converts IEnumerable To DataTable, my problem is that one off the columns allowes Nullable and then i get this exception- DataSet does not support System.Nullable <> here is part of my function-
foreach (PropertyInfo pi in pis) { if (dt.Columns.Count == 0) { foreach (PropertyInfo pi in pis) { dt.Columns.Add(pi.Name, pi.PropertyType); } }
i tried to change the function to-if (dt.Columns.Count == 0) { foreach (PropertyInfo pi in pis) { Type propType = pi.PropertyType; if (propType.IsGenericType && propType. == typeof(System.Nullable)) { propType = Nullable.GetUnderlyingType(propType); } dt.Columns.Add(pi.Name, pi.PropertyType); } }
but i'm still getting the exception: :doh: + pi {System.Nullable`1[System.DateTime] "myColumnName"} System.Reflection.PropertyInfo {System.Reflection.RuntimePropertyInfo} What i'm doing wrong?Hi, I am getting the same error. Did you figure it out? If so, can you please let me know. Thanks in advance. Ken