Click here to Skip to main content
15,906,106 members

Comments by nik varma (Top 6 by date)

nik varma 15-Dec-16 8:04am View    
Hi Richard, Thank you for the reply, but i case there will be some location id null and it is giving a error message, for the reason Convert.ToInt16(l["Location_ID"]) is coming null

Please help with the same
nik varma 14-Dec-16 2:17am View    
Thanks Richard

I found the second way and i will try your solution if its not possible with the this solution

now i am able to got the same json format but issue is that i have added a rows in sublocation table and now when i am trying to get the json data all working fine but in location of sublocation all the sublocations are coming instend of respective location of sublocation

Please help, i guess m missing something

_gloc.country = _dt.AsEnumerable()
.GroupBy(c => new { country_id = c["country_id"], country_name = c["country_name"] })
.Select(co => new Country
{
country_id = Convert.ToInt16(co.Key.country_id.ToString()),
country_name = Convert.ToString(co.Key.country_name.ToString()),
location = co.Select(l => new Location()
{
name = l["Location_Name"].ToString(),
addedon = l.IsNull("Location_Addedon") ? (DateTime?)null : Convert.ToDateTime(l["Location_Addedon"]),
createdby = l["Location_CreatedBy"].ToString(),
id = l.IsNull("Location_ID") ? (int?)null : Convert.ToInt16(l["Location_ID"]),
location_lat = l["Location_Lat"].ToString(),
location_long = l["Location_Long"].ToString(),
sub_location = co
.Select(subl => new Sub_Location()
{
id = subl.IsNull("SubLocation_ID") ? (Int16?)null : Convert.ToInt16(subl["SubLocation_ID"]),
sublocation_name = subl["SubLocation_Name"].ToString(),
addedon = subl.IsNull("SubLocation_AddedOn") ? (DateTime?)null : Convert.ToDateTime(subl["SubLocation_AddedOn"].ToString())
}).Where(x => x.id != null).ToList()
}).Where(ll => ll.id != null).ToList()
}).ToList();
nik varma 9-Oct-16 12:24pm View    
Thanks David, please can you tell me how can i bind a data from database as i have mentioned the same in above how i am trying now.. Is this correct way, what i am trying?
nik varma 9-Oct-16 4:20am View    
Thanks friend, but here my key "EG00015588" is dynamic and may continent a space so how can i make a property of it and hold in List?
nik varma 9-Oct-16 0:03am View    
inside the class the their are two list, in which i want to bond the data, as shown in the property nested list, please check the output that i want

please help if you know