Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello every one, I have a following piece of code

dt = new DataTable();
var result = from row in ObjContext.Users
select row;
dt = result.CopyToDataTable();

when I execute this I am getting this error ``DataSet does not support System.Nullable<>.``

In my table there are some blank Columns, and I must want to get its result in DataTable.

Any help is much appreciated!!
Posted
Updated 2-Apr-15 9:42am
v2
Comments
Devendra lodha 11-Nov-14 9:05am    
I also used following code from googling:

var result = from r in ObjContext.Users
select new
{
ID=r.ID,
Username= r.Username==null?"":r.Username,
Password= r.Password==null?"":r.Password,
SecLevel = r.SecLevel == null ? 3 : r.SecLevel,

Firstname = r.Firstname == null ? "" : r.Firstname,
Lastname = r.Lastname == null ? "" : r.Lastname,
BCC = r.BCC == null ? "" : r.BCC,
SenderEmail = r.SenderEmail == null ? "" : r.SenderEmail,

};
dt = result.CopyToDataTable();

but same porblem has comes.
PIEBALDconsult 11-Nov-14 9:09am    
Strings should be OK, look at other fields.
Dominic Burford 11-Nov-14 11:49am    
I'm assuming that the field SecLevel is an integer. I'm guessing that's the offending field and that the empty fields contain null instead of a default value such as 0.
Maciej Los 2-Apr-15 6:26am    
What's the structure of sql table? What's entity model?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900