I having a problem while using Left Join to bind data to gridview, maybe i got miss out somethig. below is my coding and error msg, please help me take a look, thanks
two table detail
Table Memberlist
Member_no | Member_id | Member_status
1 | lee | normal
2 | admin | admin
3 | tan | normal
Table GainPointList
gpmember_id | gp_date_start | gp_date_end
lee | 4/20/2013 9:18:17 PM | 4/20/201 9:18:17 PM
lee | 4/20/2013 9:18:17 PM | 4/20/201 9:18:17 PM
lee | 4/20/2013 9:18:17 PM | 4/20/201 9:18:17 PM
lee | 4/20/2013 9:18:17 PM | 4/20/201 9:18:17 PM
tan | 4/20/2013 9:18:17 PM | 4/20/201 9:18:17 PM
tan | 4/20/2013 9:18:17 PM | 4/20/201 9:18:17 PM
coding part
SqlCommand Cmd = new SqlCommand("Select (ML.member_no) as vmemberno, (ML.member_id) as vmemberid, COUNT(DISTINCT GPL.gpmember_id) as psmark, Min(GPL.gp_date_start) as psdatestart, Min(GPL.gp_date_end) as psdateend, (ML.member_status) as vmemberstatus From (memberlist ML LEFT JOIN gainpointlist GPL ON ML.member_id = GPL.gpmember_id) GROUP BY member_id", condatabase);
DataTable Table = new DataTable();
SqlDataAdapter Adapter = new SqlDataAdapter(Cmd);
Adapter.Fill(Table);
gvmemberinfo.DataSource = Table;
gvmemberinfo.DataBind();
ERROR MSG
Column 'memberlist.member_no' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. <br />
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br />
<br />
Exception Details: System.Data.SqlClient.SqlException: Column 'memberlist.member_no' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Source Error:
Line 89: DataTable Table = new DataTable();
Line 90: SqlDataAdapter Adapter = new SqlDataAdapter(Cmd);
Line 91: Adapter.Fill(Table); // error msg
Line 92: