I have to run a query in a SqlDataAdapter but I am having problems with syntax error near @parameterName. My code:
con.Open();
string sql ="select top @take * from"+
"(Select ProductName, CategoryName, CompanyName, UnitPrice, ROW_NUMBER() OVER(ORDER BY ProductId) AS ROW_NUM "+
"from Products as p inner join Categories as c on p.CategoryID = c.CategoryID "+
"inner join Suppliers as s on p.SupplierID = s.SupplierID "+
") as x "+
"where x.ROW_NUM > @skip ";
SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
adapter.SelectCommand.Parameters.Add("@take", SqlDbType.Int).Value = 20;
adapter.SelectCommand.Parameters.Add("@skip", SqlDbType.Int).Value = 10;
/* */
DataTable dt = new DataTable();
adapter.Fill(dt);
repProducts.DataSource = dt;
repProducts.DataBind();
con.Close();