EntityDataSource Where Clause in VB.NET

2020-04-18 03:46发布

I have a entitydatasource bound to a gridview on my webpage.

In the code behind, I am able to filter and display what I want to the gridview using the WHERE statements of the entitydatasource. One of my where statements filters by using a large OR statement, but the much more logical IN statement does not work.

For example I have employees 1-9 and I want to select employees 1, 4, and 7. In SQL I can get this two ways:

1.

SELECT * FROM table WHERE EmployeeID = 1 OR EmployeeID = 4 OR EmployeeID = 7

2.

SELECT * FROM table WHERE EmployeeID IN (1,4,7)

Both of these statements work perfectly fine for me in SQL

When using the EF, only option 1 works for selecting those particular employees. In order to create this statement, I have a for loop that creates a whereString that end up looking like this:

whereString = "it.EmployeeID = 1 OR it.EmployeeID = 4 OR it.EmployeeID = 7"
EntityDataSource.Where = whereString

If I set my whereString equal to this

whereString = "it.EmployeeID IN (1,4,7)"

it does not work. Why does this where clause that mimics the format used in the SQL code not work?

1条回答
▲ chillily
2楼-- · 2020-04-18 04:09

The "IN clause" for EntityDataSource.Where requires curly braces, rather than parentheses:

whereString = "it.EmployeeID IN {1,4,7}"
查看更多
登录 后发表回答