Last post Feb 27, 2012 04:14 AM by shafiqkr
Member
96 Points
386 Posts
Feb 27, 2012 03:38 AM|shafiqkr|LINK
Hi all,
i have a field in class as below
public int remDays { get; set; }
this get the number of days (days difference betweeen two dates)......start and end date may be null in database.
when this return null then i m getting exception here(Cannot cast DBNull.Value to type 'System.Int32'. Please use a nullable type)
var query = from o in dsResult.Tables[0].AsEnumerable() select new ban { remDays = o.Field<int>("remDays") }; List<ban> lstDisplay = new List<ban>(); lstDisplay.AddRange(query);
Star
10925 Points
2218 Posts
Feb 27, 2012 03:55 AM|Steelymar|LINK
use :
public int? remDays { get; set; }
and get the value with:
remDays.Value
Contributor
5745 Points
1899 Posts
Feb 27, 2012 04:03 AM|vinay13mar|LINK
Hi try this
after tis assign value in below way
remDays = (int)o.Field<int>("remDays")
after this assign value in below way
Feb 27, 2012 04:14 AM|shafiqkr|LINK
vinay13mar public int? remDays { get; set; }
this give me this error
Cannot cast DBNull.Value to type 'System.Int32'. Please use a nullable type...
i am sure that i have null in table and it return me null(wehn i run query in sqlserver)
Member
96 Points
386 Posts
Null data issue
Feb 27, 2012 03:38 AM|shafiqkr|LINK
Hi all,
i have a field in class as below
public int remDays { get; set; }
this get the number of days (days difference betweeen two dates)......start and end date may be null in database.
when this return null then i m getting exception here(Cannot cast DBNull.Value to type 'System.Int32'. Please use a nullable type)
var query = from o in dsResult.Tables[0].AsEnumerable()
select new ban
{
remDays = o.Field<int>("remDays")
};
List<ban> lstDisplay = new List<ban>();
lstDisplay.AddRange(query);
Star
10925 Points
2218 Posts
Re: Null data issue
Feb 27, 2012 03:55 AM|Steelymar|LINK
use :
and get the value with:
Contributor
5745 Points
1899 Posts
Re: Null data issue
Feb 27, 2012 04:03 AM|vinay13mar|LINK
Hi try this
after tis assign value in below way
V.K.Singh
Contributor
5745 Points
1899 Posts
Re: Null data issue
Feb 27, 2012 04:03 AM|vinay13mar|LINK
Hi try this
after this assign value in below way
V.K.Singh
Member
96 Points
386 Posts
Re: Null data issue
Feb 27, 2012 04:14 AM|shafiqkr|LINK
this give me this error
Cannot cast DBNull.Value to type 'System.Int32'. Please use a nullable type...
i am sure that i have null in table and it return me null(wehn i run query in sqlserver)