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中的 if(month = '', 'NO',month) as monthT
返回good或'no'或month
在C#中返回byte[]
,但如果month为空,则需要返回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 :(得分:2)
答案 1 :(得分:0)
我不是MySql专家,但为什么你不尝试演员?
CAST(if(month = '', 'NO',month) AS VARCHAR) AS monthT
更多信息: http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html