我遇到了C#的问题。 我的程序应该创建一个MYSQL查询并执行它。我现在正在寻找像2小时这样的问题而且我找不到它......
这是代码
cmd.Parameters.AddWithValue("@entryid", entryid);
cmd.Parameters.AddWithValue("@entryid2", entryid2);
cmd.Parameters.AddWithValue("@entryid3", entryid3);
cmd.Parameters.AddWithValue("@entryid4", entryid4);
cmd.Parameters.AddWithValue("@killcredit1", killcredit1);
cmd.Parameters.AddWithValue("@killcredit2", killcredit2);
cmd.Parameters.AddWithValue("@modelid1", modelid1);
cmd.Parameters.AddWithValue("@modelid2", modelid2);
cmd.Parameters.AddWithValue("@modelid3", modelid3);
cmd.Parameters.AddWithValue("@modelid4", modelid4);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@subname", subname);
cmd.Parameters.AddWithValue("@iconname", iconname);
cmd.Parameters.AddWithValue("@gossipmenuid", gossipmenuid);
cmd.Parameters.AddWithValue("@minlevel", minlevel);
cmd.Parameters.AddWithValue("@maxlevel", maxlevel);
cmd.Parameters.AddWithValue("@exp", exp);
cmd.Parameters.AddWithValue("@faction", faction);
cmd.Parameters.AddWithValue("@npcflag", npcflag);
cmd.Parameters.AddWithValue("@speedwalk", speedwalk);
cmd.Parameters.AddWithValue("@speedrun", speedrun);
cmd.Parameters.AddWithValue("@scale", scale);
cmd.Parameters.AddWithValue("@rank", rank);
cmd.Parameters.AddWithValue("@dmgschool", dmgschool);
cmd.Parameters.AddWithValue("@attacktime", attacktime);
cmd.Parameters.AddWithValue("@rattacktime", rattacktime);
cmd.Parameters.AddWithValue("@basevariance", basevariance);
cmd.Parameters.AddWithValue("@rangevariance", rangevariance);
cmd.Parameters.AddWithValue("@unitclass", unitclass);
cmd.Parameters.AddWithValue("@unitflags", unitflags);
cmd.Parameters.AddWithValue("@unitflags2", unitflags2);
cmd.Parameters.AddWithValue("@dynamicflags", dynamicflags);
cmd.Parameters.AddWithValue("@family", family);
cmd.Parameters.AddWithValue("@trainertype", trainertype);
cmd.Parameters.AddWithValue("@trainerspell", trainerspell);
cmd.Parameters.AddWithValue("@trainerclass", trainerclass);
cmd.Parameters.AddWithValue("@trainerrace", trainerrace);
cmd.Parameters.AddWithValue("@type", type);
cmd.Parameters.AddWithValue("@typeflags", typeflags);
cmd.Parameters.AddWithValue("@lootid", lootid);
cmd.Parameters.AddWithValue("@pickpocketloot", pickpocketloot);
cmd.Parameters.AddWithValue("@skinloot", skinloot);
cmd.Parameters.AddWithValue("@resistance1", resistance1);
cmd.Parameters.AddWithValue("@resistance2", resistance2);
cmd.Parameters.AddWithValue("@resistance3", resistance3);
cmd.Parameters.AddWithValue("@resistance4", resistance4);
cmd.Parameters.AddWithValue("@resistance5", resistance5);
cmd.Parameters.AddWithValue("@resistance6", resistance6);
cmd.Parameters.AddWithValue("@spell1", spell1);
cmd.Parameters.AddWithValue("@spell2", spell2);
cmd.Parameters.AddWithValue("@spell3", spell3);
cmd.Parameters.AddWithValue("@spell4", spell4);
cmd.Parameters.AddWithValue("@spell5", spell5);
cmd.Parameters.AddWithValue("@spell6", spell6);
cmd.Parameters.AddWithValue("@spell7", spell7);
cmd.Parameters.AddWithValue("@spell8", spell8);
cmd.Parameters.AddWithValue("@petspelldataid", petspelldataid);
cmd.Parameters.AddWithValue("@vehicleid", vehicleid);
cmd.Parameters.AddWithValue("@mingold", mingold);
cmd.Parameters.AddWithValue("@maxgold", maxgold);
cmd.Parameters.AddWithValue("@ainame", ainame);
cmd.Parameters.AddWithValue("@movementtype", movementtype);
cmd.Parameters.AddWithValue("@inhabittype", inhabittype);
cmd.Parameters.AddWithValue("@hoverheigh", hoverheigh);
cmd.Parameters.AddWithValue("@healthmod", healthmod);
cmd.Parameters.AddWithValue("@manamod", manamod);
cmd.Parameters.AddWithValue("@armormod", armormod);
cmd.Parameters.AddWithValue("@damagemod", damagemod);
cmd.Parameters.AddWithValue("@expmod", expmod);
cmd.Parameters.AddWithValue("@racialleader", racialleader);
cmd.Parameters.AddWithValue("@questitem1", questitem1);
cmd.Parameters.AddWithValue("@questitem2", questitem2);
cmd.Parameters.AddWithValue("@questitem3", questitem3);
cmd.Parameters.AddWithValue("@questitem4", questitem4);
cmd.Parameters.AddWithValue("@questitem5", questitem5);
cmd.Parameters.AddWithValue("@questitem6", questitem6);
cmd.Parameters.AddWithValue("@movementid", movementid);
cmd.Parameters.AddWithValue("@regenhealth", regenhealth);
cmd.Parameters.AddWithValue("@mechanicimmunmask", mechanicimmunmask);
cmd.Parameters.AddWithValue("@flagsextra", flagsextra);
cmd.Parameters.AddWithValue("@scriptname", scriptname);
#endregion
textBox_test.Text = "INSERT INTO creature_template (entry, difficulty_entry_1, difficulty_entry_2, difficulty_entry_3, KillCredit1, KillCredit2, modelid1, modelid2, modelid3, modelid4, name, subname, IconName, gossip_menu_id, minlevel, maxlevel, exp, faction, npcflag, speed_walk, speed_run, scale, rank, dmgschool, BaseAttackTime, RangeAttackTime, BaseVariance, RangeVariance, unit_class, unit_flags, unit_flags2, dynamicflags, family, trainer_type, trainer_spell, trainer_class, trainer_race, type, type_flags, lootid, pickpocketloot, skinloot, resistance1, resistance2, resistance3, resistance4, resistance5, resistance6, spell1, spell2, spell3, spell4, spell5, spell6, spell7, spell8, PetSpellDataId, VehicleId, mingold, maxgold, AIName, MovementType, InhabitType, HoverHeight, HealthModifier, ManaModifier, ArmorModifier, DamageModifier, ExperienceModifier, RacialLeader, questItem1, questItem2, questItem3, questItem4, questItem5, questItem6, movementId, RegenHealth, mechanic_immune_mask, flags_extra, ScriptName) VALUES (" + entryid + "," + entryid2 + "," + entryid3 + "," + killcredit1 + "," + killcredit2 + "," + modelid1 + "," + modelid2 + "," + modelid3 + "," + modelid4 + "," + name + "," + subname + "," + iconname + "," + gossipmenuid + "," + minlevel + "," + maxlevel + "," + exp + "," + faction + "," + npcflag + "," + speedwalk + "," + speedrun + "," + scale + "," + rank + "," + dmgschool + "," + attacktime + "," + rattacktime + "," + basevariance + "," + rangevariance + "," + unitclass + "," + unitflags + "," + unitflags2 + "," + dynamicflags + "," + family + "," + trainertype + "," + trainerspell + "," + trainerclass + "," + trainerrace + "," + type + "," + typeflags + "," + lootid + "," + pickpocketloot + "," + skinloot + "," + resistance1 + "," + resistance2 + "," + resistance3 + "," + resistance4 + "," + resistance5 + "," + resistance6 + "," + spell1 + "," + spell2 + "," + spell3 + "," + spell4 + "," + spell5 + "," + spell6 + "," + spell7 + "," + spell8 + "," + petspelldataid + "," + vehicleid + "," + mingold + "," + maxgold + "," + ainame + "," + movementid + "," + inhabittype + "," + hoverheigh + "," + healthmod + "," + manamod + "," + armormod + "," + damagemod + "," + expmod + "," + racialleader + "," + questitem1 + "," + questitem2 + "," + questitem3 + "," + questitem4 + "," + questitem5 + "," + questitem6 + "," + movementid + "," + regenhealth + "," + mechanicimmunmask + "," + flagsextra + "," + scriptname + ");";
try
{
connection.Open();
cmd.CommandText = "INSERT INTO creature_template (entry, difficulty_entry_1, difficulty_entry_2, difficulty_entry_3, KillCredit1, KillCredit2, modelid1, modelid2, modelid3, modelid4, name, subname, IconName, gossip_menu_id, minlevel, maxlevel, exp, faction, npcflag, speed_walk, speed_run, scale, rank, dmgschool, BaseAttackTime, RangeAttackTime, BaseVariance, RangeVariance, unit_class, unit_flags, unit_flags2, dynamicflags, family, trainer_type, trainer_spell, trainer_class, trainer_race, type, type_flags, lootid, pickpocketloot, skinloot, resistance1, resistance2, resistance3, resistance4, resistance5, resistance6, spell1, spell2, spell3, spell4, spell5, spell6, spell7, spell8, PetSpellDataId, VehicleId, mingold, maxgold, AIName, MovementType, InhabitType, @HoverHeight, HealthModifier, ManaModifier, ArmorModifier, DamageModifier, ExperienceModifier, RacialLeader, questItem1, questItem2, questItem3, questItem4, questItem5, questItem6, movementId, RegenHealth, mechanic_immune_mask, flags_extra, ScriptName) VALUES (@entryid, @entryid2, @entryid3, @entryid4 @killcredit1, @killcredit2, @modelid1, @modelid2, @modelid3, @modelid4, @name, @subname, @iconname, @gossipmenuid, @minlevel, @maxlevel, @exp, @faction, @npcflag, @speedwalk, @speedrun, @scale, @rank, @dmgschool, @attacktime, @rattacktime, @basevariance, @rangevariance, @unitclass, @unitflags, @unitflags2, @dynamicflags, @family, @trainertype, @trainerspell, @trainerclass, @trainerrace, @type, @typeflags, @lootid, @pickpocketloot, @skinloot, @resistance1, @resistance2, @resistance3, @resistance4, @resistance5, @resistance6, @spell1, @spell2, @spell3, @spell4, @spell5, @spell6, @spell7, @spell8, @petspelldataid, @vehicleid, @mingold, @maxgold, @ainame, @movementtype, @inhabittype, @hoverheigh, @healthmod, @manamod, @armormod, @damagemod, @expmod, @racialleader, @questitem1, @questitem2, @questitem3, @questitem4, @questitem5, @questitem6, @movementid, @regenhealth, @mechanicimmunmask, @flagsextra, @scriptname)";
cmd.ExecuteNonQuery();
MessageBox.Show("NPC Erfolgreich erstellt.");
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}
我得到了这个MYSQL异常:
命令执行期间遇到致命错误。
答案 0 :(得分:2)
我发现你的查询有些问题。
您的查询中有一个需要删除的流氓@
符号。在列中,它看起来像这样:
...MovementType, InhabitType, @HoverHeight, HealthModifier, ManaModifier...
您在参数列表中缺少逗号:
@entryid3, @entryid4 @killcredit1
^
Here