I’m trying to select data from db with using this code:
getForecastsCommand.CommandText = @"SELECT TOP @Count * FROM Forecasts Order by [ForecastId] DESC";
var countParam = getForecastsCommand.CreateParameter();
countParam.ParameterName = "@Count";
countParam.Value = count;
countParam.DbType = DbType.Int32;
getForecastsCommand.Parameters.Add(countParam);
But it isn’t work:
Incorrect syntax near '@Count'.
Why isn’t it work?
Please try this
SELECT TOP (@Count) * FROM Forecasts Order by [ForecastId] DESCPlease, note that @count is surrounded by parenthesis.