Table character encoding - exception in application

Posted by zgnilec on Stack Overflow See other posts from Stack Overflow or by zgnilec
Published on 2012-03-27T03:19:55Z Indexed on 2012/03/27 5:29 UTC
Read the original article Hit count: 191

Filed under:
|
|
|

I have a code:

CREATE TABLE IF NOT EXISTS Person
(
   name varchar(24) ...
)
CHARACTER SET utf8 COLLATE utf8_polish_ci;

This works OK in my application, but I read if someone put in name field a string that contains character wchich code is greater than 127, database will use 2 bytes (or more) to store this character. So i think, i will change character set to utf16:

CHARACTER SET utf16 COLLATE utf16_polish_ci;

But now when I run my application, exception apears: KeyNotFoundException. It apears exactly at these instructions:

MySqlCommand komenda = baza.Polaczenie.CreateCommand ();
komenda.CommandText  = zapytanie;

MySqlDataReader dr = komenda.ExecuteReader (); // HERE, at execute reader method

if (dr.Read ()) ...

1) Anyone had similar problem? 2) Any idea how to use always 2 bytes/char in database field?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET