DNDタイプのゲーム用に書き留めるのではなく、すべての情報を追跡できるようにC#でプログラムを作成しています。私は問題なく新しいプレーヤーを挿入および削除することができますが、プレーヤーを更新することになると、これは私が得るエラーです
「クエリ式の構文エラー(演算子がありません)'@newPlayerName playerLevel = @newPlayerLevel heroID = @newHeroId playerInventoryID = @newPlayerInventoryIDcampaignID=@newCampaignID'。」
これがupdateメソッドの私のコードです
public static Boolean UpdatePlayer(Player oldPlayer,
Player newPlayer)
{
OleDbConnection connection = DBConnection.GetConnection();
OleDbCommand command;
string statement =
"UPDATE Player SET " +
"playerName = @newPlayerName " +
"playerLevel = @newPlayerLevel " +
"heroID = @newHeroId " +
"playerInventoryID = @newPlayerInventoryID " +
"campaignID = @newCampaignID " +
"WHERE ID = @oldID " +
"AND playerName = @oldPlayerName " +
"AND playerLevel = @oldPlayerLevel " +
"AND heroID = @oldHeroID " +
"AND playerInventoryID = @oldPlayerInventoryID " +
"AND campaignID = @oldCampaignID ";
command = new OleDbCommand(statement, connection);
command.Parameters.AddWithValue("@newPlayerName", newPlayer.PlayerName);
command.Parameters.AddWithValue("@newPlayerLevel", newPlayer.Level);
command.Parameters.AddWithValue("@newHeroID", newPlayer.HeroID);
command.Parameters.AddWithValue("@newPlayerInventoryID", newPlayer.PlayerInventoryID);
command.Parameters.AddWithValue("@newCampaignID", newPlayer.CampaignID);
command.Parameters.AddWithValue("@oldID", oldPlayer.ID);
command.Parameters.AddWithValue("@oldPlayerName", oldPlayer.PlayerName);
command.Parameters.AddWithValue("@oldPlayerLevel", oldPlayer.Level);
command.Parameters.AddWithValue("@oldHeroID", oldPlayer.HeroID);
command.Parameters.AddWithValue("@oldPlayerInventoryID", oldPlayer.PlayerInventoryID);
command.Parameters.AddWithValue("@oldCampaignID", oldPlayer.CampaignID);
try
{
connection.Open();
int count = command.ExecuteNonQuery();
if (count > 0)
return true;
else
return false;
}
catch (OleDbException e)
{
throw e;
}
finally
{
connection.Close();
}
}
そして、これがその関数を呼び出しているコードです
private void SavePlayers()
{
if (lstPlayers.SelectedIndex > -1)
{
int parsedInt;
Player edititedPlayer = new Player();
edititedPlayer.PlayerName = txtPlayerName.Text;
edititedPlayer.HeroID =
heroes[cboHero.SelectedIndex].ID;
edititedPlayer.CampaignID =
campaigns[lstCampaigns.SelectedIndex].ID;
edititedPlayer.ID = players[lstPlayers.SelectedIndex].ID;
edititedPlayer.PlayerInventoryID =
players[lstPlayers.SelectedIndex].PlayerInventoryID;
if (Int32.TryParse(txtPlayerLevel.Text, out parsedInt))
{
edititedPlayer.Level = parsedInt;
PlayerDB.UpdatePlayer((Player)lstPlayers.SelectedItem,
edititedPlayer);
}
}