2013-05-13 105 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;"在連接字符串

希望這有助於你....

相關問題