I would like to do this request :
public int UpdateOneColumn(string dbName, string tableName, string columnName, string newValue, string whereColumnName, string whereColumnNameValue)
{
string sql = @"update @tableName set @columnName = @newValue where @whereColumnName = @whereColumnNameValue";
return connection.Execute(sql, new {tableName, columnName, newValue, whereColumnName, whereColumnNameValue });
}
but I get an error
tableName must be declared
Does someone know how to correctly declare my variables "tableName, columnName, newValue, whereColumnName and whereColumnNameValue" ?
Is this function correct? (I'm not sure I can do update @tableName
and where @whereColumnName
)
public int UpdateOneColumn(string dbName, string tableName, string setColumn, object setValue, string whereColumn, object whereValue)
{
string sql = $"UPDATE {tableName} SET {setColumn} = @s WHERE {whereColumn} = @w";
return connection.Execute(sql, new { s = setValue, w = whereValue });
}