Building a SQL parameter query - LIKE% in .cs and grid view
I am trying to implement admin and operator login (india, australia, america), now the operator id starts with "IND123" "AUS123" and "AM123"
when the india operator registers, it can only see the details of members with id 'IND%', the same applies to Australian and American users
and when admin logs in, he can see details of members with id 'IND%' or 'AUS%' or 'AM%'
I have a table that defines the role ie admin or operator and their prefix (IND, AUS respectively)
On the login page, I created a session for the role and the prefix PREFIX = myReader ["Prefix"]. ToString (); Session ["LoginRole"] = myReader ["Role"]. ToString (); Session ["LoginPrefix"] = String.Concat (PREFIX + "%"); works great
On the main page (after login) I need to count the number of members, so I wrote
string prefix = Session["LoginPrefix"].ToString();
string role = Session["LoginRole"].ToString();
if (role.Equals("ADMIN"))
StrMemberId = "select count(*) from MemberList";
else
StrMemberId = "select count(*) from MemberList where MemberID like '"+prefix+"'";
thatworks is great too
Problem: 1. I want the constructor StrMemberId = "select count (*) from MemberList where MemberID is like '@prefix +'";
myCommd.Parameters.AddWithValue (@ prefix, prefix); What does not work
2 Displaying items in a gridview I need to give a condition (something like if (role.Equals ("ADMIN")) shows all the members that show the member depending on the operator prefix) a list of members in operator and admin mode - where to put the condition in gridview how to apply these
suggest anything Relationship
Indranil
a source to share