如何从asp.net向mysql workbench插入值unicode

时间:2014-10-10 16:50:01

标签: mysql asp.net mysql-workbench

我使用procedure将数据从asp.net插入mysql workbench。插入时有数据值的问题。数据值使用unicode UFT8。但是当我插入表格时,它破坏了字体。 我不知道在插入数据时如何修复字体。

创建表MYSQL Workbench 6.2:

CREATE TABLE Story(
    ID_Story int primary key AUTO_INCREMENT,
    Name varchar(200) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NULL DEFAULT NULL ,
    DateTimeNew datetime ,
    Image varchar(300) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NULL DEFAULT NULL ,
    Description LONGTEXT NULL,
    Rate float NULL,
    Author varchar(40) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NULL DEFAULT NULL ,
    Readed int NULL,
    Cate tinyint default '0', 
    tinhtrang nvarchar(20) default 'Đang ra'
) CHARSET=utf8;

代码程序:

CREATE PROCEDURE Update_Story(p_Name varchar(200)  CHARACTER SET 'utf8' 
    ,p_Image varchar(300)  CHARACTER SET 'utf8'
    ,p_Description longtext
    ,p_Rate double
    ,p_Author varchar(40)  CHARACTER SET 'utf8' 
    ,p_Cate tinyint unsigned
    ,p_return varchar(100)  CHARACTER SET 'utf8'  ) 
begin
    set p_Name = (select REPLACE(p_Name,'<h2>',''));
    set p_Name = (select REPLACE(p_Name,'</h2>',''));
    if(select COUNT(ID_Story) from Story where Name = p_Name) = 0
    then
        insert into Story(Name,Image,Description,Rate,Author,Cate) values  
        (p_Name,p_Image,p_Description,p_Rate,p_Author,p_Cate);
        set p_return = Concat(N'0|Tạo mới|' ,  last_insert_id());
    else 
        set p_return = Concat(N'1|Đa tồn tại |' , (select  ID_Story from Story where Name = p_Name limit 1));
    END IF;
END

代码插入Asp.net的MySQL

 String connectionstring = @"Data Source=localhost;user id=root;password=123456;;database=doctruyen;";
            using (MySqlConnection cns = new MySqlConnection(connectionstring))
            {
                MySqlCommand cmd = new MySqlCommand("Update_Story", cns);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("p_Name","13132àáạảã");
                cmd.Parameters.AddWithValue("p_Image", "1312àáạảã");
                cmd.Parameters.AddWithValue("p_Description", "1312àáạảã");
                cmd.Parameters.AddWithValue("p_Rate", "12");
                cmd.Parameters.AddWithValue("p_Author", "1312àáạảã");
                cmd.Parameters.AddWithValue("p_Cate", "1");
                cmd.Parameters.Add("p_return", MySqlDbType.Text).Direction = ParameterDirection.Output;
                cns.Open();
                cmd.ExecuteNonQuery();
                Response.Write("goi" +cmd.Parameters["p_return"].Value.ToString());
                cns.Close();
                cmd.Dispose();
                Response.Write("con");
            }

结果插入(插件中的字体已损坏):

1   13132àá??ã      13132àá??ã  1312àá??ã   12  1312àá??ã       1   Đang ra

0 个答案:

没有答案