c# and MySQL select string from db and utf-8 table

that the code i use to create Connection with the datebase

private static string MySqlUsername, MySqlPassword, MySqlDatabase, MySqlHost;
        private static string ConnectionString;
        public static void CreateConnection(string user, string password, string database, string host)
        {
            MySqlUsername = user;
            MySqlHost = host;
            MySqlPassword = password;
            MySqlDatabase = database;
            ConnectionString = "Server=" + MySqlHost + ";Database='" + MySqlDatabase + "';Username='" + MySqlUsername + "';Password='" + MySqlPassword + "';Pooling=true; Max Pool Size = 160000; Min Pool Size = 0;CHARSET=utf8";
        }
        public static MySql.Data.MySqlClient.MySqlConnection MySqlConnection
        {
            get
            {
                MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
                conn.ConnectionString = ConnectionString;
                return conn;
            }
        }

my problem is when i select string from utf-8 datebase with that code

public void accf()
        {
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd.Select("med").Where("Name", MName.Text).Or("UID", MUID.Text).Execute();
            MySqlReader r = new MySqlReader(cmd);
            if (r.Read())
            {
                CharName.Text = r.ReadString("Name");
            }
            else
            {
                fnf.ForeColor = Color.Red;
                fnf.Text = "can't found anything";
                fnf.Visible = true;
            }
        }

whatever the string at Name was number it can read it but when it was anyname the program told me that can't found anything and here is the table

DROP TABLE IF EXISTS `med`;
CREATE TABLE `med` (
  `Name` varchar(16) CHARACTER SET utf8 NOT NULL,
  `UID` bigint(18) unsigned NOT NULL,
  `Substance` varchar(45) CHARACTER SET utf8 NOT NULL,
  `Expiry` date DEFAULT NULL,
  `Type` tinyint(5) unsigned DEFAULT '10',
  `Note` varchar(18) DEFAULT NULL,
  PRIMARY KEY (`UID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

sorry for bad English i hope that can help to solve my problem

Answers


You could try ExecuteScalar() instead of Execute() in case your table is returning more than one row.


Need Your Help

Why can't I return a string from an AsyncTask?

android eclipse android-asynctask

I am trying to read an online txt file from my Dropbox and put its content into a string with an Asynctask but I can't manage to return my string.

Responsive web design by using css or javascript?

javascript html css responsive-design

I am going to make a website that is using responsive design. I read some information about css media query. What I wanna do is that the layout of my webpage should looks difference by using differ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.