2013-05-13 58 views
3

我有一个方法是调用MySQL程序。下面是程序的一部分:Convert.ToString返回`System.Byte []`而不是实际的数据作为GROUP_CONCAT返回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(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"]); 

据如下返回值:

enter image description here

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

+0

该列的数据类型是什么?它看起来是某种二进制类型。 – 2013-05-13 08:07:05

+0

occured_event_id是INT类型。但是程序正在返回逗号分隔的ID。 – Ajinkya 2013-05-13 08:10:09

+0

分享您编写的一些C#代码以读取PROC中的数据... – Pandian 2013-05-13 08:11:54

回答

3

做出如下修改我的程序它的工作后:

(SELECT group_concat(CONVERT(occured_event_id, CHAR(8)) separator ', ') 
FROM alert_rule_event 
WHERE alert_rule_id = AR.id) AS OccuredEventIds 
2

我会尝试将您的参数铸造到group_concatvarchar首先作为documentation says that it converts binary parametersBLOB

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 
+0

在对程序进行此更改之后,它给了我SQL语法错误 – Ajinkya 2013-05-13 08:26:54

+0

尝试'char(20)'。 – 2013-05-13 08:48:21

+0

这一个为我工作,谢谢你好,先生。 – 2015-05-12 05:35:55

0

GROUP_CONCAT返回BLOB类型,因此只有你得到字节输出,

溶胶 - 1:group_concat_max_len系统变量来512

变化值,并重新启动mysql服务

请看这里:Why GROUP_CONCAT returns BLOB?

OR

溶胶2:

SET "respect binary flags=false;"在连接字符串

希望这有助于你....

相关问题