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.
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.
您可能希望在WHERE子句中使用OR而不是AND。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.