简体   繁体   English

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

[英]Error: GetCharacters System.InvalidCastException: Specified cast is not valid server

Error 错误

System.InvalidCastException: Specified cast is not valid. System.InvalidCastException:指定的强制转换无效。

Line 71 71号线

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

Code Sample Below 下面的代码示例

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;
                       }

Not sure why you are trying do this conversion. 不知道为什么要尝试执行此转换。 But, try this 但是,尝试一下

Convert.ToUInt32(Convert.ToInt32(dr["partner"]))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XML文件错误错误:System.InvalidCastException:指定的强制转换无效 - XML File Error Error : System.InvalidCastException: Specified cast is not valid 指定的转换无效-System.InvalidCastException - Specified cast is not valid - System.InvalidCastException System.InvalidCastException:指定的强制转换无效 - System.InvalidCastException: Specified cast is not valid System.InvalidCastException:指定的强制转换无效。错误 - System.InvalidCastException: Specified cast is not valid. Error 消息错误:System.InvalidCastException:指定的强制转换无效10 - Message error : System.InvalidCastException: Specified cast is not valid 10 “ System.InvalidCastException:指定的转换无效”-DateTime - “System.InvalidCastException: Specified cast is not valid” - DateTime System.InvalidCastException:指定的强制转换在.ExecuteScalar上无效 - System.InvalidCastException: Specified cast is not valid at .ExecuteScalar Linq To数据集错误System.InvalidCastException:指定的强制转换无效 - Linq To Data set error System.InvalidCastException: Specified cast is not valid System.InvalidCastException:&#39;指定的强制转换无效。 - System.InvalidCastException: 'Specified cast is not valid.' System.InvalidCastException:指定的强制转换无效(linq查询) - System.InvalidCastException: Specified cast is not valid (linq query)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM