Menu

#28 TEXT field returns System.Byte[] in ToString()

open-fixed
nobody
None
5
2006-10-20
2006-02-24
k__
No

With a MySQL TEXT field, calling:

MySQLDataReader["FieldName"].ToString()

returns System.Byte[] instead of the actual string
value.

A work-around is to instead call:

strValue = MySQLDataReader.GetString
(MySQLDataReader.GetOrdinal("FieldName"));

The previous version of MySQLDriverCS correctly
converted ToString() for a TEXT field. However, the
new version fails to do this. This should be brought
back into ToString().

Discussion

  • Nobody/Anonymous

    Logged In: NO

    Where is old version?
    I have same error with you.

     
  • Nobody/Anonymous

    Logged In: NO

    I believe to correct this, you need to edit C:\Program
    Files\MySQLDriverCS\source\MySQLDriverCS\MySQLDataReader.cs
    in Visual Studio and set the following function shown
    below. Then do a rebuild-all and include the new .dll file
    in your project. The dll is located in C:\Program
    Files\MySQLDriverCS\dll\MySQLDriverCS.dll

    public string GetString( int i )
    {
    //Convert Text field to string
    if (this[i] is byte[])
    {
    return System.Text.Encoding.Default.GetString((byte
    [])this[i]);
    }
    else
    {
    return Convert.ToString( this[i] );
    }
    }

     
  • k__

    k__ - 2006-10-20
    • status: open --> open-fixed
     
  • k__

    k__ - 2006-10-20

    Logged In: YES
    user_id=1460953

    Sorry, forgot to login. I posted the solution code below.

     

Log in to post a comment.