2010-10-10 100 views
1
SELECT Trainer.id AS idTrainer, surname, lastname, name, 
if(month = '', 'NO',month) as monthT, quarter, halfyear, year, id_Person, photo 
FROM Trainer, Person 
WHERE Trainer.id_Person = Person.id 

在phpMyAdmin回報良好或「否」或月如何將byte []轉換爲varchar?

在C#if(month = '', 'NO',month) as monthT返回byte[],但我需要回到NO如果一個月爲空,否則返回month

我的C#代碼如下所示:

string sql = @" SELECT Trainer.id AS idTrainer, surname, lastname, name, if(month = '', 'NO',month) as monthT, quarter, halfyear, year, id_Person, photo 
       FROM Trainer, Person 
       WHERE Trainer.id_Person = Person.id"; 
using (MySqlConnection connection = ConnectToDataBase.GetConnection()) 
{ 
    MySqlCommand command = new MySqlCommand(sql, connection); 
    MySqlDataAdapter adapter = new MySqlDataAdapter(); 

    connection.Open(); 
    adapter.SelectCommand = command; 
} 
+0

,問題是......? – CesarGon 2010-10-10 14:21:02

+0

你的問題很難理解。你可以發佈CREATE TABLE語句嗎? C#是否返回字節[]而不是字符串,還是你希望它返回byte []而不是字符串?你爲什麼使用空而不是_NULL_? – 2010-10-10 14:21:57

+0

如何將字節[]轉換爲字符串...意味着sql – Mediator 2010-10-10 14:22:14

回答

0

我沒有mysql專家,但你爲什麼不嘗試投?

CAST(if(month = '', 'NO',month) AS VARCHAR) AS monthT 

更多在這裏: http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html

+0

您在SQL語法中有錯誤;檢查與您的MySQL服務器版本對應的手冊,以在'VARCHAR'附近使用正確的語法作爲monthT,quarter,halfyear,year,id_Person,照片 '在第1行 – Mediator 2010-10-10 15:08:04

+0

這是例外 – Mediator 2010-10-10 16:17:41

+0

正如我所說,我不是MySql專家,我沒有安裝任何MySql。這只是給你提示如何解決它......我確信你可以弄清楚如何使它運行;-) – gsharp 2010-10-10 19:39:40