Mediator
Mediator

Reputation: 15378

How Convert byte[] to varchar?

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;
}

Upvotes: 1

Views: 7584

Answers (2)

Eugene Cheverda
Eugene Cheverda

Reputation: 8930

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

Upvotes: 3

gsharp
gsharp

Reputation: 27927

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

Upvotes: 0

Related Questions