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
if(month = '', 'NO',month) as monthT
in phpmyadmin return good or 'no' or month
In a C# returns byte[]
, but I need return NO
if开发者_如何学编程 month is empty or else return the month
.
My C# code looks like this:
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;
}
While researching I have found out that there is the bug with VARCHAR using CAST. The solution is to use CHAR instead of VARCHAR.
Proof links:
Using Conversion Functions
Bug #34564 CAST does not accept varchar type
Cast Functions and Operators
I'm no MySql expert but why you don't try to cast?
CAST(if(month = '', 'NO',month) AS VARCHAR) AS monthT
more here: http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html
精彩评论