在MYSQL中存储表情符号 - 超出列的范围值

时间:2013-04-27 08:28:40

标签: c# mysql

我想将以下表情符号存储在mysql中

   Emoticons                  Score    

    %-(          ,            -1
    %-)          ,             1
    (-:          ,             1
    :*(          ,            -1    

这是以逗号分隔的文件。
我写下以下代码来stroe这个文件

private void button1_Click(object sender, EventArgs e)
        {
            string[] lines = File.ReadAllLines("D:\\EmoticonLookupTable.txt");
            foreach (var line in lines)
            {
                var data = line.Split(new[] { ',' }, 2);
                string  Emoticons  = data[0].Trim();
                int Score  = int.Parse(data[1].Trim());

                StoreRecord( Emoticons,Score);
            }
        }     

private void StoreRecord(string word,int Score)
        {
            var conStr = "server=localhost; database=zahid; password=zia; User Id=root;";
            using (var connection = new MySqlConnection(conStr))
            using (var command = connection.CreateCommand())
            {
                connection.Open();
                command.CommandText =
                @"INSERT INTO za 
            (Emoticons,Score) 
          VALUES 
            (@Emoticons,@Score)";
                command.Parameters.AddWithValue("@Emoticons", Emoticons);
                command.Parameters.AddWithValue("@Score", Score);

                command.ExecuteNonQuery();
            }
        }    

但此代码会出现以下错误 的错误
超出第1行的“得分”列的范围值 谢谢你... ...

1 个答案:

答案 0 :(得分:1)

您可能尝试将负数存储在数据库的unsigned int列中。

您的代码没问题(int数据类型是有符号整数,因此它支持负数),但您可以在某处使用无符号整数。

其他原因可能是太多了。

MSDN说:

  

整数变量存储为带符号的32位(4字节)整数   范围从-2,147,483,648到2,147,483,647。