3

我有一种方法是调用MySQL过程。以下是部分程序:

SELECT AR.alert_id AS AlertId,
        AR.rule_id AS RuleId,
        AR.name AS RuleName,
        AR.rule_type AS RuleType, 
        AR.description AS Description, 
        (SELECT group_concat(occured_event_id separator ', ') 
            FROM alert_rule_event
            WHERE alert_rule_id = AR.id) AS OccuredEventIds,
FROM alert_rule AR

C#代码:

alertRuleEntity.AlertId = Convert.ToInt32(dtAlertRuleEntityList.Rows[index]["AlertId"]);
alertRuleEntity.RuleId = Convert.ToInt32(dtAlertRuleEntityList.Rows[index]["RuleId"]);
alertRuleEntity.RuleName = Convert.ToString(dtAlertRuleEntityList.Rows[index]["RuleName"]);
alertRuleEntity.RuleType = Convert.ToString(dtAlertRuleEntityList.Rows[index]["RuleType"]);
alertRuleEntity.Description = Convert.ToString(dtAlertRuleEntityList.Rows[index]["Description"]);
alertRuleEntity.OccuredEventIds = Convert.ToString(dtAlertRuleEntityList.Rows[index]["OccuredEventIds"]);

它返回值如下:

在此处输入图像描述

它能够正确读取所有列值。但是在列的情况下,OccuredEventIds它给出的值System.Byte[]而不是它的实际值。可能是什么问题呢?

4

3 回答 3

3

在对我的程序进行以下更改后,它起作用了:

(SELECT group_concat(CONVERT(occured_event_id, CHAR(8)) separator ', ') 
FROM alert_rule_event
WHERE alert_rule_id = AR.id) AS OccuredEventIds
于 2013-05-13T09:48:45.587 回答
2

我会尝试将您的参数转换group_concatvarchar第一个,因为文档说它将二进制参数转换BLOB.

SELECT AR.alert_id AS AlertId,
        AR.rule_id AS RuleId,
        AR.name AS RuleName,
        AR.rule_type AS RuleType, 
        AR.description AS Description, 
        (SELECT group_concat(cast(occured_event_id as char(20)) separator ', ') 
            FROM alert_rule_event
            WHERE alert_rule_id = AR.id) AS OccuredEventIds,
FROM alert_rule AR
于 2013-05-13T08:20:33.737 回答
0

Group_Concat 返回 BLOB 类型,所以只有你得到 Bytes 作为输出,

溶胶-1:

group_concat_max_len将系统变量的值更改为512 并重启MySql服务

见这里: 为什么 GROUP_CONCAT 返回 BLOB?

或者

溶胶-2:

"respect binary flags=false;"在您的连接字符串中设置

希望这可以帮助你....

于 2013-05-13T08:26:43.057 回答