Q: where clause to SqlDataAdapter1

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have SqlDataAdapter1 and DataSet11 in my asp.net application and I am
using then in many function to select and update the table. Is there any way
to restrict the query of SqlDataAdapter1 with the username?
I have a username field in the table and I need to modify do something like
SELECT * FROM Customer WHERE username=’currentUserNameâ€, this way a single
user can see only records attached to him/her.
I can create a new adapter and dataset objects each time I need it, but my
existing functions: insert and update get so much complicated. Any suggestion?
Thanks,
Jim.
 
Change the SQL to be "SELECT * FROM Customer WHERE username = @username"
and then somewhere (maybe Page_Load) add the parameter:

string theUsername = User.Identity.Name; // or from somewhere else, like
a TextBox.Text
SqlDataAdapter1.SelectCommand.Parameters.Add("@username", theUsername);

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Thanks for the reply. It seems
sqlDataAdapter1.SelectCommand.Parameters["@username"].Value = theUsername;
is the right way.
 
Back
Top