Reputation: 291
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?
Upvotes: 0
Views: 1388
Reputation: 54
Please try this SELECT TOP (@Count) * FROM Forecasts Order by [ForecastId] DESC
Please, note that @count is surrounded by parenthesis.
Upvotes: 2
Reputation: 91376
That syntax looks like a Microsoft Access database. If it is, it does not support parameters for TOP. You will have to build the string.
@"SELECT TOP " + Count + " * FROM Forecasts Order by [ForecastId] DESC";
Upvotes: 0