Hi I am trying to create a searchbox that searches a ListView I managed to do just that and it works if I leave it to be searched only by username.As soon as I replace the username with a parameter the code does not work anymore.Here is my code:
string searchSelectBox = SearchSelectDropDown.SelectedItem.Text;
GetAllUsersFromDb.SelectCommand =
"SELECT aspnet_Users.UserName, aspnet_Roles.RoleName, "
+ "aspnet_Membership.Email, aspnet_Membership.LastLoginDate "
+ "FROM aspnet_Users "
+ "INNER JOIN aspnet_UsersInRoles "
+ "ON aspnet_Users.UserId = aspnet_UsersInRoles.UserId "
+ "INNER JOIN aspnet_Roles "
+ "ON aspnet_UsersInRoles.RoleId = aspnet_Roles.RoleId "
+ "INNER JOIN aspnet_Membership "
+ "ON aspnet_Users.UserId = aspnet_Membership.UserId "
+ "WHERE @SelectField LiKE @Param";
GetAllUsersFromDb.SelectParameters.Clear();
GetAllUsersFromDb.SelectParameters.Add("SelectField" , searchSelectBox);
GetAllUsersFromDb.SelectParameters.Add("Param" , SearchBox.Text);
GetAllUsersFromDb.DataBind();
textListView.DataBind();
The values that the searchSelectBox can take are Username , Rolename and Email
If I replace the @SelectField with username and type a corect username the sear works but as it is it does not.
What is the problem here?
Try this