SELECT時に問題は無し
sjisで作ったテーブルに括弧株のコードである0x878Aを使ってINSERTし,それからSELECTして表示する.
using System; using MySql.Data.MySqlClient; namespace CNTNS { class ConnectorNETTest { public static void Main() { Console.WriteLine("Hello World!"); string myConnectionString = "server=127.0.0.1;uid=root;" + "pwd=;database=test;charset=sjis;"; MySqlConnection conn = new MySqlConnection(); conn.ConnectionString = myConnectionString; conn.Open(); MySqlDataReader reader = null; MySqlCommand cmd = null; cmd = new MySqlCommand("DROP TABLE IF EXISTS t1", conn); reader = cmd.ExecuteReader(); reader.Close(); cmd = new MySqlCommand("CREATE TABLE t1 (c1 INT, c2 CHAR(1)) DEFAULT CHARSET=sjis", conn); reader = cmd.ExecuteReader(); reader.Close(); cmd = new MySqlCommand("INSERT INTO t1 VALUES (1, 0x878A)", conn); reader = cmd.ExecuteReader(); reader.Close(); cmd = new MySqlCommand("SELECT * FROM t1", conn); reader = cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader.GetString(0) + "=" + reader.GetString(1)); } reader.Close(); conn.Close(); Console.WriteLine("Hello MySQL!"); } } }
実行結果
D:\share\workspace\current\CSharp>ConnectorNETTest2.exe Hello World! 1=㈱ Hello MySQL!
続きがいろいろあるのだけどとりあえずここまで.