[Help] 5095 MySql Error

06/26/2011 07:32 killersub#1
okay so I've been getting this error most usual lately. it's a MySql error ofc but can't seem to find the mistake at.

the error is:

Code:
Input string was not in a correct format.
and I checked all my inputted strings and I think they're all in the correct format.

the last edits I made were in Database.cs where I changed and added some things such as Mobs and MobSpawns aswell as NPCs and NPC actions.

here are some of the things I added feel free to check for the correct/incorrect formats:

Code:
public static void LoadActions()
        {
            MySqlCommand cmd = new MySqlCommand("SELECT * FROM `actions`", DatabaseConnection.NewConnection());
            MySqlDataReader DR = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR.Read())
            {
                Struct.Actions A = new Struct.Actions();
                A.ID = Convert.ToInt32("id");
                A.IDNext = Convert.ToInt32("id_next");
                A.IDNextFail = Convert.ToInt32("id_nextfail");
                A.Type = Convert.ToInt32("type");
                A.Data = Convert.ToInt32("data");
                A.Param = Convert.ToString("param");
                if (!Nano.NpcActions.ContainsKey(A.ID))
                    Nano.NpcActions.Add(A.ID, A);
            }
            Console.WriteLine("[WorldServer] Loaded " + Nano.NpcActions.Count + " Npc Actions into the World.");
        }
        public static void LoadMonsters()
        {
            MySqlCommand cmd = new MySqlCommand("SELECT * FROM `monsters` ", DatabaseConnection.NewConnection());
            MySqlDataReader DR = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR.Read())
            {
                Struct.MonsterInfo MI = new Struct.MonsterInfo();
                MI.ViewDistance = Convert.ToInt32("jrange");
                MI.AttackRange = Convert.ToInt32("arange");
                MI.AttackSpeed = Convert.ToInt32("attack_speed");
                MI.Defense = Convert.ToInt32("pdef");
                MI.Dodge = Convert.ToInt32("dodge");
                MI.ID = Convert.ToInt32("id");
                MI.Level = Convert.ToInt32("level");
                MI.MagicID = Convert.ToInt32("atype");
                MI.MaxAttack = Convert.ToInt32("atkmax");
                MI.MaxHP = Convert.ToInt32("hp");
                MI.MDefense = Convert.ToInt32("mdef");
                MI.Mesh = Convert.ToInt32("mech");
                MI.MinAttack = Convert.ToInt32("atkmin");
                MI.Name = Convert.ToString("name");
                MI.Speed = Convert.ToInt32("speed");
                MI.MinSilvers = Convert.ToInt32("avgmoney");
                MI.MaxSilvers = Convert.ToInt32("drop_money");
                MI.DropItemType = Convert.ToInt32("drop_itemtype");
                MI.DropChance = Convert.ToDouble("drop_chance");
                if (!Nano.MonsterTypes.ContainsKey(MI.ID))
                {
                    Nano.MonsterTypes.Add(MI.ID, MI);
                }
            }
            Console.WriteLine("[WorldServer] Loaded " + Nano.MonsterTypes.Count + " Monster Types into the World.");
        }
        public static void LoadMonsterSpawns()
        {
            MySqlCommand cmd = new MySqlCommand("SELECT * FROM `mobspawns` ", DatabaseConnection.NewConnection());
            MySqlDataReader DR = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            int TotalSpawns = 0;
            while (DR.Read())
            {
                MonsterSpawn MS = new MonsterSpawn();
                MS.Map = Convert.ToInt32("Map");
                MS.MobID = Convert.ToInt32("ID");
                MS.SpawnID = Convert.ToInt32("UniSpawnID");
                MS.SpawnNumber = Convert.ToInt32("NumberToSpawnf");
                if (MS.Map == 1015)
                    MS.SpawnNumber = Convert.ToInt32("NumberToSpawnf");
                MS.MaxSpawnNumber = MS.SpawnNumber * 2;
                if (MS.Map == 1015)
                    MS.MaxSpawnNumber = MS.SpawnNumber;
                if (MS.MobID >= 900 && MS.MobID <= 912)
                {
                    MS.SpawnNumber = 1;
                    MS.MaxSpawnNumber = 1;
                }
                TotalSpawns += MS.SpawnNumber;
                MS.X = Convert.ToInt32("x-start");
                MS.XStop = Convert.ToInt32("x-stop");
                MS.Y = Convert.ToInt32("y-start");
                MS.YStop = Convert.ToInt32("y-stop");
                MS.RespawnInterval = Convert.ToInt32("rest_secs");
                if (!Nano.MonsterSpawns.ContainsKey(MS.SpawnID))
                {
                    Nano.MonsterSpawns.Add(MS.SpawnID, MS);
                }
            }
            Console.WriteLine("[WorldServer] Loaded " + Nano.MonsterSpawns.Count + " unique monster spawns.");
            Console.WriteLine("[WorldServer] Will theoretically spawn " + TotalSpawns + " monsters into the world.");
        }
        public static void LoadNpcs()
        {
            MySqlCommand cmd = new MySqlCommand("SELECT * FROM `npcs` ", DatabaseConnection.NewConnection());
            MySqlDataReader DR = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR.Read())
            {
                Struct.NPC NPC = new Struct.NPC();
                NPC.ID = Convert.ToInt32("id");
                NPC.OwnerID = Convert.ToInt32("ownerid");
                NPC.PlayerID = Convert.ToInt32("playerid");
                NPC.Name = Convert.ToString("name");
                NPC.Type = Convert.ToInt32("type");
                NPC.LookFace = Convert.ToInt32("lookface");
                NPC.Map = Convert.ToInt32("mapid");
                NPC.X = Convert.ToInt32("cellx");
                NPC.Y = Convert.ToInt32("celly");
                NPC.Task0 = Convert.ToInt32("task0");
                NPC.Task1 = Convert.ToInt32("task1");
                NPC.Task2 = Convert.ToInt32("task2");
                NPC.Task3 = Convert.ToInt32("task3");
                NPC.Task4 = Convert.ToInt32("task4");
                NPC.Task5 = Convert.ToInt32("task5");
                NPC.Task6 = Convert.ToInt32("task6");
                NPC.Task7 = Convert.ToInt32("task7");
                NPC.Data0 = Convert.ToInt32("data0");
                NPC.Data1 = Convert.ToInt32("data1");
                NPC.Data2 = Convert.ToInt32("data2");
                NPC.Data3 = Convert.ToInt32("data3");
                NPC.DataString = Convert.ToString("datastr");
                NPC.LinkID = Convert.ToInt32("linkid");
                NPC.Life = Convert.ToInt32("life");
                NPC.MaxLife = Convert.ToInt32("maxlife");
                NPC.Base = Convert.ToInt32("base");
                NPC.Sort = Convert.ToInt32("sort");
                NPC.ItemID = Convert.ToInt32("itemid");
                if (!Nano.Npcs.ContainsKey(NPC.ID))
                    Nano.Npcs.Add(NPC.ID, NPC);
            }
            Console.WriteLine("[WorldServer] Loaded " + Nano.Npcs.Count + " Npcs into the World.");
        }
Any help would be appreciated :)
06/26/2011 10:01 { Angelius }#2
there are 2 things to rethink about.

converting a char string to a uint/int/etc value gives you the same error .
A.IDNext = Convert.ToInt32("id_next");

"id_next" is a string value that that should contain numbers not letters so once you use the "" you turned it to a letters which means the convert sees it as letters (i d _ n e x t) lets say that the (id_next) is a int and the A.IDNext is a uint you can just do something like A.IDNext = (uint)(id_next)

and the other thing is in that load void you are using a sql reader which reads directly from the database so the convert.towhatever is useless

MySqlDataReader DR = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

that means that your sql reader = DR

so you go

A.IDNext = DR.ReadUInt32("id_next");
or
A.IDNext = DR.ReadUInt16("id_next");
depending on what is the value that you are reading int/uint/ushort/etc.


good luck .
06/26/2011 19:21 killersub#3
Quote:
Originally Posted by { Angelius } View Post
there are 2 things to rethink about.

converting a char string to a uint/int/etc value gives you the same error .
A.IDNext = Convert.ToInt32("id_next");

"id_next" is a string value that that should contain numbers not letters so once you use the "" you turned it to a letters which means the convert sees it as letters (i d _ n e x t) lets say that the (id_next) is a int and the A.IDNext is a uint you can just do something like A.IDNext = (uint)(id_next)

and the other thing is in that load void you are using a sql reader which reads directly from the database so the convert.towhatever is useless

MySqlDataReader DR = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

that means that your sql reader = DR

so you go

A.IDNext = DR.ReadUInt32("id_next");
or
A.IDNext = DR.ReadUInt16("id_next");
depending on what is the value that you are reading int/uint/ushort/etc.


good luck .
In other words just change all the Converts to Read from the MySqlDataReader?
06/27/2011 06:33 { Angelius }#4
Quote:
Originally Posted by killersub View Post
In other words just change all the Converts to Read from the MySqlDataReader?
Exactly . cus the way you did it earlier it not reading anything at all as no values provided .
06/27/2011 10:11 Korvacs#5
Quote:
Originally Posted by killersub View Post
In other words just change all the Converts to Read from the MySqlDataReader?
Currently your not reading data from the DataReader your just trying to convert text into numbers...

You need to learn some fundamentals for C#..