Wednesday, April 17, 2013

Data Text Field Showing System.Byte[] in Radio Button List when concatenating multiple columns

While working on one of the project's i came across a scenario when data text field i binded in radio button list showed data on local but online it showed System.Byte[] instead of text.I was using Mysql database and for data text field i was concatenating 3 values .When i run that query on mysql it returned me data.I got expected results while running on local but when same code was deployed on server an unexpected thing occur. After lot of investigation and goggling i found one interesting thing that it was not the problem with code,it was merely a mysql .NET connector, version 5.1.6.Actually on local i was having .NET connector, version 3.51 According to mysql.com it is not a bug ,but it is expected behaviour.According to mysql.com if we are having any query that concatenates two or more columns ,Then one of the scenario will occur:-
  • mysql> SELECT CONCAT("Tonci", " ", "Grgin") AS Name; Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are non-binary strings, the result is a non-binary string.
  • mysql> SELECT CONCAT("Tonci ", 1, " Grgin") AS Name; BINARY flag is set (this is where your problem is!) This will return binary string.
  • Now here is the solution to the problem: Cast the result of concatenate query as Char and then use it.Hence the issue of System.Byte array in Data Text Field will be solved. mysql> SELECT CAST(CONCAT("Tonci ", 1, " Grgin") AS CHAR) AS Name; For further details Visit:http://bugs.mysql.com/bug.php?id=37485

    No comments :

    Post a Comment