除了一个列之外,所有列都在DataGrid中正确显示。我在MySqlWorkbench中运行了这个SQL查询,它的工作原理是没有错:
string query = @"SELECT c.*,cc.CountryName ,(Select UserName FROM users WHERE User_ID = c.CreatedByUser) AS CreatedBy,
(select GROUP_CONCAT(AreaDescription) from pxpcountycodes where countyid=c.id) as AreaDescription,
(select GROUP_CONCAT(cmr.AccountCode)) as Member " +
" FROM counties c " +
" LEFT JOIN Countries cc ON c.CountryID = cc.ID " +
" LEFT JOIN PXPCountyCodes PXPc on c.ID = PXPc.CountyID" +
" LEFT JOIN customer cmr ON PXPc.MemberID = cmr.ID " +
" WHERE c.Company_ID = ?companyID ";
DataGrid的代码:
<asp:DataGrid runat="server" CssClass="tblResults" OnItemDataBound="dgList_ItemCreated" AllowSorting="true" OnSortCommand="dgList_Sort" ID="dgList" DataKeyField="ID" AutoGenerateColumns="false">
<HeaderStyle CssClass="tblResultsHeader" />
<AlternatingItemStyle BackColor="#EEEEEE" />
<Columns>
<asp:BoundColumn DataField="CountyName" HeaderText="County Name/PostCode" SortExpression="c.CountyName" ></asp:BoundColumn>
<asp:BoundColumn DataField="Description" HeaderText="Description" SortExpression="c.Description"></asp:BoundColumn>
<asp:BoundColumn DataField="Member" HeaderText="Member" SortExpression="Member"/>
<asp:BoundColumn DataField="CountryName" HeaderText="Country" SortExpression="cc.CountryName"></asp:BoundColumn>
<asp:BoundColumn DataField="CountyPostCode" HeaderText="County/PostCode" SortExpression="c.CountyPostCode"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
问题在于Member
列。此列显示公司列表,例如列应显示CONWAY,NGWCLARE
。有些专栏试图展示大约5家公司,因此导致问题的长度是什么?
Grid背后的代码:
DataSet ds = Lookups.County.GetAllCounties(Company.Current.CompanyID, ddlSearchBy.SelectedItem.Value, txtSearchBy.Text, IsActive, rbl_both.Checked, OrderBy, false, -1, "", 0);
if (ds.Tables[0].Rows.Count > 0)
{
dgList.DataSource = ds.Tables[0];
dgList.DataBind();
}
答案 0 :(得分:1)
尝试此查询。 CASTING GROUP_CONCAT的输出AS CHAR应解决问题。
string query = @"SELECT c.*,cc.CountryName ,(Select UserName FROM users WHERE User_ID = c.CreatedByUser) AS CreatedBy,
(select GROUP_CONCAT(AreaDescription) from pxpcountycodes where countyid=c.id) as AreaDescription,
CAST(GROUP_CONCAT(cmr.AccountCode) As CHAR) as Member " +
" FROM counties c " +
" LEFT JOIN Countries cc ON c.CountryID = cc.ID " +
" LEFT JOIN PXPCountyCodes PXPc on c.ID = PXPc.CountyID" +
" LEFT JOIN customer cmr ON PXPc.MemberID = cmr.ID " +
" WHERE c.Company_ID = ?companyID ";