简体   繁体   English

MS Access更新记录

[英]MS Access update record

I'm trying to update the records in an Access database where the column "Group" matches the argument. 我正在尝试更新Access数据库中“组”列与参数匹配的记录。

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. 在这种情况下,我假设的问题是我正在尝试更新要迭代的同一列,因此我需要先使用Select查询,只是不确定这样做的正确方法。

Thanks in advance. 提前致谢。

You aren't providing the parameters in the query. 您没有在查询中提供参数。

Try: 尝试:

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

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

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