This is my code:
// Taken from combobox selection.
string columnName = cboCrudSearchColumn.Text.ToString();
// Taken from textbox selection.
string searchValue = txtCrudSearch.Text.ToString();
dgvLoadTable.DataSource = EntityName
.TableName
.Where(columnName + " = @0", searchValue )
.ToList();
Now, this works fine when searchValue is a string (ex: ABC), but when it is a numeric value (ex: 30) it gives the following exception: Operator '=' incompatible with operand types 'Decimal' and 'String. How can I overcome this problem?
You use parametrized query and pass as parameter string value, so this parameter have type string and you get error with operand types.
for solving just pass decimal value, like
dgvLoadTable.DataSource = EntityName
.TableName
.Where(columnName + " = @0", int.Parse(searchValue) )
.ToList();