473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Q: where clause to SqlDataAdapter1

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.

Nov 19 '05 #1
2 976
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("@use rname", theUsername);

-Brock
DevelopMentor
http://staff.develop.com/ballen
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.


Nov 19 '05 #2
Thanks for the reply. It seems
sqlDataAdapter1.SelectCommand.Parameters["@username"].Value = theUsername;
is the right way.

"Brock Allen" wrote:
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("@use rname", theUsername);

-Brock
DevelopMentor
http://staff.develop.com/ballen
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.


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold {...
5
by: Google Jenny | last post by:
Hi. My colleague and I have followed the procedure to populate a form with data from a database, using this code: private void bindGrid() { sqlConnection1.Open();...
2
by: aj70000 | last post by:
This is my query select ano,max(date),a_subject from MY_TAB where table_name='xyz' and ano=877 group by a_subject,ano order by a_subject ANO max(Date) A_Subject 877 2005-01-20...
7
by: JJ_377 | last post by:
Can someone tell me why SQL seems to ignore my order by clause? I tried to run through the debugger, but the debugger stops at the select statement line and then returns the result set; so, I have...
3
by: Mike D | last post by:
What am I doing wrong? I want to be able to add parameters to my WHERE clause in my sqlDataAdapter. I also want to use LIKE. (ie. style_cd like "%123%" ...
26
by: GreatAlterEgo | last post by:
Hi, This is my query which is embedded in a COBOL program. EXEC SQL SELECT DATE, AGE, DURATION, AMT INTO :LDATE, :L.AGE, :L.DURATION, :L.AMT FROM TAB1 WHERE CODE = :KEY.CODE AND...
2
by: Jim.Mueksch | last post by:
I am having a problem with using calculated values in a WHERE clause. My query is below. DB2 gives me this error message: Error: SQL0206N "APPRAISAL_LESS_PRICE" is not valid in the context where...
5
by: pwiegers | last post by:
Hi, I'm trying to use the result of a conditional statement in a where clause, but i'm getting 1)nowhere 2) desperate :-) The query is simple: -------- SELECT idUser,...
6
by: jackal_on_work | last post by:
Hi Faculties, I have two queries which give me the same output. -- Query 1 SELECT prod.name, cat.name FROM products prod INNER JOIN categories cat ON prod.category_id = cat.id WHERE cat.id...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.