【发布时间】:2011-09-23 23:15:41
【问题描述】:
我正在编写一些代码更新数据库,其中包含一些占位符的 SQL 语句。但它似乎没有更新这些占位符。
我收到以下错误:
Cannot update '@columnName'; field not updateable
方法如下:
public void updateDoctorTableField(string columnName, string newValue, string vendorNumber) {
sqlStatement = "update Doctor set @columnName = @newValue where `VENDOR #` = @vendorNumber;";
try {
_command = new OleDbCommand(sqlStatement, _connection);
_command.Parameters.Add("@columnName", OleDbType.WChar).Value = columnName;
_command.Parameters.Add("@newValue", OleDbType.WChar).Value = newValue;
_command.Parameters.Add("@vendorNumber", OleDbType.WChar).Value = vendorNumber;
_command.ExecuteNonQuery();
} catch (Exception ex) {
processExeption(ex);
} finally {
_connection.Close();
}
}
【问题讨论】:
标签: asp.net sql sql-server database