Reputation: 167
I have a gridview which should display only usernames based on the email written in textbox1 and textbox2. How can I do this? I bound the gridview to a sql data source and in tht, I used the where clause like
SELECT [Username] FROM [Users] WHERE (([Email] = @Email) AND ([Email] = @Email2))
Where control ID on email is textbox 1 and control ID of email2 is textbox 2. But the result is null. The gridview is not displaying anything.
Upvotes: 1
Views: 733
Reputation: 40516
SELECT [Username] FROM [Users] WHERE [Email] in (@Email, @Email2)
is the correct SELECT statement.
Alternatively, you could do
SELECT [Username] FROM [Users] WHERE (([Email] = @Email) OR ([Email] = @Email2))
(note the OR instead of AND)
The problem with your SELECT is that it retrieves the rows that are equal to both @Email and @Email2. You could test that by trying to set the same email value in both text boxes - that should bring some results.
Upvotes: 4
Reputation: 135789
You probably want an OR instead of an AND in the WHERE clause.
Upvotes: 0