2013-04-27 30 views
2

我想存储以下表情在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个
感谢advace ...

+1

数据库表中Score列的数据类型是什么? – Blablablaster 2013-04-27 08:33:24

+0

确保得分是签名数据类型。 – rocky 2013-04-27 08:39:33

+0

什么是你的MySQL表结构?请向我们展示您的'DESCRIBE TABLE za'输出。 – GregD 2013-04-27 09:25:35

回答

1

你可能尝试存储在数据库unsigned int列负数。

你的代码是好的(int数据类型是有符号整数,所以它支持负数),但是你可以在某处有无符号整数。

其他原因可能数量太大。

MSDN说:

整数变量存储为带符号的32位(4字节)整数 从2,147,483,648通过2147483647测距值。