我有一种方法是调用 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[]
而不是实际值。可能是什么问题?
答案 0 :(得分:3)
在对我的程序进行以下更改后,它起作用了:
(SELECT group_concat(CONVERT(occured_event_id, CHAR(8)) separator ', ')
FROM alert_rule_event
WHERE alert_rule_id = AR.id) AS OccuredEventIds
答案 1 :(得分:2)
我会先尝试将参数转换为group_concat
至varchar
作为documentation says that it converts binary parameters至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
答案 2 :(得分:0)
Group_Concat返回BLOB类型,只有你得到Bytes作为输出,
Sol-1:
将group_concat_max_len
系统变量的值更改为512
并重新启动MySql服务
请参阅此处: Why GROUP_CONCAT returns BLOB?
OR
Sol-2:
在您的连接字符串中设置"respect binary flags=false;"
希望这可以帮助你......