I am using following function for retrieving record on choice. I gave table my column name and value and it shows the result. but the problem is, Its not getting column name as parameter like:
public List<Products> ListAllProducts(string searchOption, string searchValue)
{
db.ClearParameters();
db.AddParameter(db.MakeInParam("@ColumnName", DbType.String, 50, searchOption));
db.AddParameter(db.MakeInParam("@Value", DbType.String, 50, searchValue));
string query = @"SELECT *
FROM [Products]
WHERE @ColumnName LIKE '%'+@Value+'%'";
ds = db.GetDataSet(query);
//Rest of code but above query is not executing
}
but when I use query like this:
string query = @"SELECT *
FROM [Products]
WHERE "+searchOption+" LIKE '%'+@Value+'%'";
It runs fine and give me result. I read this, this and this one specially, but got no idea. Kindly guide me.