简体   繁体   中英

MS Access update record

I'm trying to update the records in an Access database where the column "Group" matches the argument.

The method I'm using at the moment is the following:

public void RenameGroup(string oldName, string newName)
{
    OpenConnection();
    command.Connection = con;
    command.CommandText = "Update [Data] SET [Group] = ? WHERE [Group] = ?";
    command.Parameters.Add("@oldName", OleDbType.Char).Value = oldName;
    command.Parameters.Add("@newName", OleDbType.Char).Value = newName;
    command.ExecuteNonQuery();
    CloseConnection();
}

The issue in this case I'm assuming it's that I'm trying to update the same column I'm iterating over and I need to use a Select query first, just not sure what would be the right way of doing it.

Thanks in advance.

You aren't providing the parameters in the query.

Try:

command.CommandText = "Update [Data] SET [Group] = @newName WHERE [Group] = @oldName";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM