need Null value to sotre in int [modified]
-
Hi if no element return from this i need "loct" to be null int? loct = (from s in sdc.Locations where s.Name == listViewEx4.Items[i].SubItems[7].Text select s.Location_ID).SingleOrDefault(); First() return error message Sequence contains no elements SingleOrDefault() return 0 i need null from this sequence how can i do
modified on Wednesday, November 12, 2008 10:46 AM
-
Hi if no element return from this i need "loct" to be null int? loct = (from s in sdc.Locations where s.Name == listViewEx4.Items[i].SubItems[7].Text select s.Location_ID).SingleOrDefault(); First() return error message Sequence contains no elements SingleOrDefault() return 0 i need null from this sequence how can i do
modified on Wednesday, November 12, 2008 10:46 AM
-
mutafa81 wrote:
how can i do
no, try to compile this:
int n = null;
Now, read the compiler error message and think about your question. Good luck.
led mike
-
Hi if no element return from this i need "loct" to be null int? loct = (from s in sdc.Locations where s.Name == listViewEx4.Items[i].SubItems[7].Text select s.Location_ID).SingleOrDefault(); First() return error message Sequence contains no elements SingleOrDefault() return 0 i need null from this sequence how can i do
modified on Wednesday, November 12, 2008 10:46 AM
Im guessing your field "Location_ID" is an int rather than an int?, in which case the default is 0 which can be assigned to the int? you could try this:
int temp = (from s in sdc.Locations
where s.Name == listViewEx4.Items[i].SubItems[7].Text
select s.Location_ID).SingleOrDefault();int? loct = (temp == 0) ? null : temp;
-
Im guessing your field "Location_ID" is an int rather than an int?, in which case the default is 0 which can be assigned to the int? you could try this:
int temp = (from s in sdc.Locations
where s.Name == listViewEx4.Items[i].SubItems[7].Text
select s.Location_ID).SingleOrDefault();int? loct = (temp == 0) ? null : temp;
Thank you will try
J4amieC wrote:
Im guessing your field "Location_ID" is an int rather than an int?, in which case the default is 0 which can be assigned to the int? you could try this: int temp = (from s in sdc.Locationswhere s.Name == listViewEx4.Items[i].SubItems[7].Textselect s.Location_ID).SingleOrDefault();int? loct = (temp == 0) ? null : temp;