2016-06-14 42 views
0

错误错误:GetCharacters System.InvalidCastException:指定的转换无效服务器

System.InvalidCastException: Specified cast is not valid.

线71

Tamer.Partner = GetDigimon((uint)(int)dr["partner"]); 

代码示例下面

public static List<Character> GetCharacters(uint AcctId) 
{ 
    List<Character> chars = new List<Character>(); 
    try 
    { 
     using (MySqlCommand cmd = new MySqlCommand(
      "SELECT * FROM `chars` WHERE `accountId` = @id" 
      , Connect())) 
     { 
      cmd.Parameters.AddWithValue("@id", AcctId); 

      using(MySqlDataReader dr = cmd.ExecuteReader()) 
      { 
       if (dr.HasRows) 
       { 
        while (dr.Read()) 
        { 
         Character Tamer = new Character(); 
         Tamer.AccountId = AcctId; 
         Tamer.CharacterId = Convert.ToUInt32((int)dr["characterId"]); ; 
         Tamer.Model = (CharacterModel)(int)dr["charModel"]; 
         Tamer.Name = (string)dr["charName"]; 
         Tamer.Level = (int)dr["charLv"]; 
         Tamer.Location = new Helpers.Position((short)(int)dr["map"], (int)dr["x"], (int)dr["y"]); 

         Tamer.Partner = GetDigimon((uint)(int)dr["partner"]); 
         if (dr["mercenary1"] != DBNull.Value) 
         { 
          int mercId = (int)dr["mercenary1"]; 
          Digimon merc = GetDigimon((uint)mercId); 
          Tamer.DigimonList[1] = merc; 
         } 
         if (dr["mercenary2"] != DBNull.Value) 
         { 
          int mercId = (int)dr["mercenary2"]; 
          Digimon merc = GetDigimon((uint)mercId); 
          Tamer.DigimonList[2] = merc; 
         } 
+0

错误发生在第71行。 –

+0

谢谢Sateesh! –

+0

欢迎您!请将其标记为答案,这将回答您的问题。 – DarkKnight

回答

0

不知道为什么你正在尝试做这个转换。但是,试试这个

Convert.ToUInt32(Convert.ToInt32(dr["partner"])) 
相关问题