Datagrid列中显示的System.Byte[]

本文关键字:Byte System 显示 Datagrid | 更新日期: 2023-09-27 18:26:38

除一列外,所有列都在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 ";

数据网格的代码:

<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家公司,那么长度会造成问题吗?

网格背后的代码:

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();
        }

Datagrid列中显示的System.Byte[]

尝试此查询。CASTing GROUP_CONCT的输出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 ";