I am trying to pass the variable as a table name in sql command text. This is code i tried
string tableName = string.Empty;
for (int m = dateDebut.Month; m <= dateFin.Month; m++)
{
sqlCommand.Parameters.Clear();
tableName = "DynamicPosition" + m;
sqlCommand.CommandText = "SELECT ProfileId, FloorId FROM @tableName WHERE ProfileId = @profileId AND LastUpdate >= @dateDebut AND LastUpdate <= @dateFin";
sqlCommand.Parameters.AddWithValue("@tableName", tableName);
}
This is the error I am getting
Must declare the table variable \"@tableName\"