c# - Retrieving records from table where a column may have multiple rows of data -
i have database several tables , using following query return record matches string(name).
in mhp
table there name field(primary key), num_sites
, few more, these ones concerned with.
in mhp_parcel_info
table there many fields 1 of them being name(foreign key)
. there parcel_id
field , in case there may 1 parcel 1 name, there may many parcels name.
as query return 1 of rows instances there multiple parcels name.
what is: if there more 1 parcel name, have parcels put list(so can display in listbox on form).
my sql skills limited , don’t know how go doing this.
select mhp_parcel_info.*, mhp.num_sites mhp_parcel_info inner join mhp on " + "(mhp_parcel_info.mhp_name = mhp.mhp_name) mhp_parcel_info.mhp_name='" + strvalue + "'"
this not can directly in sql. there's no way select data in parent/child structure in sql query - have post-processing step.
since tagged c# , winforms i'm assuming inside .net app. need execute query have above, in c# can use linq groupby extension method on result group results list of igrouping objects use name key, , has of parcel info items in list.
even better, if using (or can use) linq sql or entity framework can write linq query fetches data database , grouping @ once.
Comments
Post a Comment