c# - System.Byte[] 显示在 Datagrid 列中

标签 c# mysql asp.net datagrid

除一列外,所有列均在 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 家公司,那么长度是否会导致问题?

网格背后的代码:

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

最佳答案

尝试这个查询。将 GROUP_CONCAT 的输出转换为 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 ";

关于c# - System.Byte[] 显示在 Datagrid 列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34264653/

相关文章:

php - 我从数据库中提取的整个文本没有以 unicode 呈现,而是出现了像 "&#2309"这样的文本?

Mysql让爷爷孙子一路下来

c# - GridView 行编辑

.net - 禁用 ASP.NET 事件验证

c# - 缺少 DocumentFormat.OpenXml.Extensions

c# - 使用 C#.Net 播放 .WMV

php - PHP 表中的总和列

c# - 单个包上的 DNN 多个模块

c# - 从输入数据流中查找重复计数...

asp.net - AppFabric 缓存连接类型和协议(protocol)