2

我想在mysql中存储以下表情

   Emoticons                  Score    

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

这是逗号分隔的文件。
我写了下面的代码来读取这个文件

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 行的“分数
”列的值超出范围,
感谢提前...

4

1 回答 1

1

You probably trying to store negative number in unsigned int column in database.

Your code is OK (int data type is signed integer, so it supports negative number), but you can have unsigned integer somewhere.

Other reason may be too big number.

MSDN says:

Integer variables are stored as signed 32-bit (4-byte) integers ranging in value from -2,147,483,648 through 2,147,483,647.

于 2013-04-27T14:37:26.867 回答