Q: where clause to SqlDataAdapter1

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.
 
B

Brock Allen

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);
 
G

Guest

Thanks for the reply. It seems
sqlDataAdapter1.SelectCommand.Parameters["@username"].Value = theUsername;
is the right way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top