473,657 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting Data

Hi, I have 2 tables, One containing a list of Companies (ID, Name) Another
Containing a list of companies a user has acces to (IdUser, IdCompany) The
question is how can I load all the companies into a checkBoxList Control and
only check the companies that the user currently has access to?

Thanks,
Nov 19 '05 #1
9 1245
Use a JOIN in the SQL statement and then specify a WHERE clause with the
IdUser

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"CCORDON" <tc******@hotma il.com> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
Hi, I have 2 tables, One containing a list of Companies (ID, Name) Another
Containing a list of companies a user has acces to (IdUser, IdCompany) The
question is how can I load all the companies into a checkBoxList Control
and only check the companies that the user currently has access to?

Thanks,

Nov 19 '05 #2
Sorry, I dont understand how that will allow me to check only the ones the
user has access to in my CheckListBox

Thanks.

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:uO******** ******@TK2MSFTN GP10.phx.gbl...
Use a JOIN in the SQL statement and then specify a WHERE clause with the
IdUser

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"CCORDON" <tc******@hotma il.com> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
Hi, I have 2 tables, One containing a list of Companies (ID, Name)
Another Containing a list of companies a user has acces to (IdUser,
IdCompany) The question is how can I load all the companies into a
checkBoxList Control and only check the companies that the user currently
has access to?

Thanks,


Nov 19 '05 #3
"CCORDON" <tc******@hotma il.com> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
Hi, I have 2 tables, One containing a list of Companies (ID, Name) Another
Containing a list of companies a user has acces to (IdUser, IdCompany) The
question is how can I load all the companies into a checkBoxList Control
and only check the companies that the user currently has access to?


Use a query like this in SQL Server:

SELECT Companies.ID, Companies.Name, CompanyAccess.I dUser
FROM Companies LEFT OUTER JOIN CompanyAccess
ON Companies.ID = CompanyAccess.I dCompany
WHERE CompanyAccess.I dUser = @IdUser

This will return three columns: ID, Name and IdUser. IdUser will either be
the Id of the user you're checking for, or it will be NULL if the user has
no access. Use the first two columns as the text and value of the
CheckBoxList, and set the checkboxes based on the IdUser column.

John Saunders
Nov 19 '05 #4
My bad...misunders tood,
How about this, when you loop through the dataset to build the list check
the IdUser and if it matches the logged in user then set the Checked=True
property?

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"CCORDON" <tc******@hotma il.com> wrote in message
news:u$******** ******@TK2MSFTN GP09.phx.gbl...
Sorry, I dont understand how that will allow me to check only the ones the
user has access to in my CheckListBox

Thanks.

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:uO******** ******@TK2MSFTN GP10.phx.gbl...
Use a JOIN in the SQL statement and then specify a WHERE clause with the
IdUser

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"CCORDON" <tc******@hotma il.com> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
Hi, I have 2 tables, One containing a list of Companies (ID, Name)
Another Containing a list of companies a user has acces to (IdUser,
IdCompany) The question is how can I load all the companies into a
checkBoxList Control and only check the companies that the user
currently has access to?

Thanks,



Nov 19 '05 #5
That sounds good...Ill give it a try.

Thanks,

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:uy******** *****@TK2MSFTNG P12.phx.gbl...
My bad...misunders tood,
How about this, when you loop through the dataset to build the list check
the IdUser and if it matches the logged in user then set the Checked=True
property?

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"CCORDON" <tc******@hotma il.com> wrote in message
news:u$******** ******@TK2MSFTN GP09.phx.gbl...
Sorry, I dont understand how that will allow me to check only the ones
the user has access to in my CheckListBox

Thanks.

"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:uO******** ******@TK2MSFTN GP10.phx.gbl...
Use a JOIN in the SQL statement and then specify a WHERE clause with the
IdUser

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"CCORDON" <tc******@hotma il.com> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
Hi, I have 2 tables, One containing a list of Companies (ID, Name)
Another Containing a list of companies a user has acces to (IdUser,
IdCompany) The question is how can I load all the companies into a
checkBoxList Control and only check the companies that the user
currently has access to?

Thanks,



Nov 19 '05 #6
Thanks, I am trying that query but only get the list of COmanies that the
user has access to, not all the companies.

Thanks,

"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
"CCORDON" <tc******@hotma il.com> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
Hi, I have 2 tables, One containing a list of Companies (ID, Name)
Another Containing a list of companies a user has acces to (IdUser,
IdCompany) The question is how can I load all the companies into a
checkBoxList Control and only check the companies that the user currently
has access to?


Use a query like this in SQL Server:

SELECT Companies.ID, Companies.Name, CompanyAccess.I dUser
FROM Companies LEFT OUTER JOIN CompanyAccess
ON Companies.ID = CompanyAccess.I dCompany
WHERE CompanyAccess.I dUser = @IdUser

This will return three columns: ID, Name and IdUser. IdUser will either be
the Id of the user you're checking for, or it will be NULL if the user has
no access. Use the first two columns as the text and value of the
CheckBoxList, and set the checkboxes based on the IdUser column.

John Saunders

Nov 19 '05 #7
"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:uy******** *****@TK2MSFTNG P12.phx.gbl...
My bad...misunders tood,
How about this, when you loop through the dataset to build the list check
the IdUser and if it matches the logged in user then set the Checked=True
property?


What query are you suggesting he use? It must be a query which returns all
of the companies and which also indicates which companies the particular
user has access to.

In fact, I should expand on my earlier post:

SELECT Companies.ID, Companies.Name,
CompanyAccess.I dUser, CompanyAccess.I dCompany
FROM Companies LEFT OUTER JOIN CompanyAccess
ON Companies.ID = CompanyAccess.I dCompany
WHERE CompanyAccess.I dUser = @IdUser

This presumes that the primary key for the CompanyAccess table is the
compound key (IdUser, IdCompany).

Keep in mind that he wants a set of checkboxes. When the user checks a box
which had not previously been checked, then a new CompanyAccess row should
be added. But if the user clears a checkbox which had previously been
checked, the corresponding CompanyAcccess row needs to be deleted. By
including the primary key of that table in the query, the row can easily be
deleted in this case.

John Saunders

Nov 19 '05 #8
"CCORDON" <tc******@hotma il.com> wrote in message
news:u3******** ******@TK2MSFTN GP12.phx.gbl...
Thanks, I am trying that query but only get the list of COmanies that the
user has access to, not all the companies.
Whoops. You're correct. Please try:

SELECT c.ID, c.Name, (CASE WHEN a.IdUser IS NULL THEN 0 ELSE 1 END) as
HasAccess, a.IdUser, a.IdCompany
FROM Company AS c LEFT OUTER JOIN
(SELECT * FROM CompanyAccess
WHERE IdUser = @IdUser) AS a
ON c.ID = a.IdCompany

John Saunders

Thanks,

"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
"CCORDON" <tc******@hotma il.com> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
Hi, I have 2 tables, One containing a list of Companies (ID, Name)
Another Containing a list of companies a user has acces to (IdUser,
IdCompany) The question is how can I load all the companies into a
checkBoxList Control and only check the companies that the user
currently has access to?


Use a query like this in SQL Server:

SELECT Companies.ID, Companies.Name, CompanyAccess.I dUser
FROM Companies LEFT OUTER JOIN CompanyAccess
ON Companies.ID = CompanyAccess.I dCompany
WHERE CompanyAccess.I dUser = @IdUser

This will return three columns: ID, Name and IdUser. IdUser will either
be the Id of the user you're checking for, or it will be NULL if the user
has no access. Use the first two columns as the text and value of the
CheckBoxList, and set the checkboxes based on the IdUser column.

John Saunders


Nov 19 '05 #9
THANK YOU!!!! :) THAT Query was just what I was looking for. Everything
works grear now. Thank you all.-
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
"CCORDON" <tc******@hotma il.com> wrote in message
news:u3******** ******@TK2MSFTN GP12.phx.gbl...
Thanks, I am trying that query but only get the list of COmanies that the
user has access to, not all the companies.


Whoops. You're correct. Please try:

SELECT c.ID, c.Name, (CASE WHEN a.IdUser IS NULL THEN 0 ELSE 1 END) as
HasAccess, a.IdUser, a.IdCompany
FROM Company AS c LEFT OUTER JOIN
(SELECT * FROM CompanyAccess
WHERE IdUser = @IdUser) AS a
ON c.ID = a.IdCompany

John Saunders

Thanks,

"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
"CCORDON" <tc******@hotma il.com> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
Hi, I have 2 tables, One containing a list of Companies (ID, Name)
Another Containing a list of companies a user has acces to (IdUser,
IdCompany) The question is how can I load all the companies into a
checkBoxList Control and only check the companies that the user
currently has access to?

Use a query like this in SQL Server:

SELECT Companies.ID, Companies.Name, CompanyAccess.I dUser
FROM Companies LEFT OUTER JOIN CompanyAccess
ON Companies.ID = CompanyAccess.I dCompany
WHERE CompanyAccess.I dUser = @IdUser

This will return three columns: ID, Name and IdUser. IdUser will either
be the Id of the user you're checking for, or it will be NULL if the
user has no access. Use the first two columns as the text and value of
the CheckBoxList, and set the checkboxes based on the IdUser column.

John Saunders



Nov 19 '05 #10

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

Similar topics

5
3355
by: Axial | last post by:
Question: How to select columns from Excel-generated XML when some cells are empty. I've found examples where rows are to be selected, but I can't seem to extrapolate from that to selecting columns when some cells are empty. Is there a way to use the ss:Index to account for the missing <Cell elements? Thank you for any suggestions. ====================
0
1221
by: Kim | last post by:
Hello, I am selecting data from a text file in the following format: INSERT INTO SELECT * FROM " & sSource & " IN '' " & _ "'text;Database=" & sPath & ";FMT=Delimited;HDR=No' " & _ "WHERE = '01'" Variable names are used for the file name, etc. But the problem lies in the "SELECT *". We have strings that are larger than 254
1
2562
by: Ramesh | last post by:
hi, I am selecting fields from three table for manupulating data and i want to display total number of records selected. But i am always getting -1 value, eventhough 1000 of records are selected. Below is my code. here strSelectSQL value is strSelectSQL = "Select emp.Empno, emp.FirstName, emp.LastName, emp.DB, emp.DOJ,emp.Grade,emp.yearofexperience,
6
2053
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I need to use parts of the tables in datagrids, and here is where my problem lies
1
2234
by: Jay | last post by:
Hi All, My users are complaining about the page refreshing when they are selecting multiple rows in a datagrid. Has anyone tried to manage this using javascript? I tried smartnavigation but that caused me other problems. Any ideas? Thanks, Jay
9
1728
by: rickou812 | last post by:
What I am attempting to do is create a form field in which a company name can be selecting from a drop down box. When selecting I want to display the information from my database about the selected company. I am releatively new to php and mysql, but I have learned how to create, input, and display data, but can not seem to figure out how to do the above. I have a page at http://www.cashsurveysnow.com/company.php with examples of a drop...
2
3318
Chittaranjan
by: Chittaranjan | last post by:
Hi All, I have a problem and hope I can get the better solution from here. I have a form written in HTML and I need to write that in perl so the main problem I am facing is that I need to generate some fields according the data I will select from the drop down list so basically I have drop down list which will ask for the number of students information I want to enter and after selecting a value from the number of students drop down it...
2
1976
by: larry | last post by:
I am working on a DB for family data, and in this application the data spans variable amount of rows in multiple tables (one for the adults data, one for "family", one for the kids, another for employment schedule, and another for businesses, etc.). I was thinking on selecting the entire family (IDs of all the related records) and storing them in a session array for easy access (from script to script) as I edit the data, but am wondering...
2
1354
by: yogeshtiwarijbp | last post by:
when i select data from the drop down list box and display data in the datagrid the first data in the dropdownlistbox not shown the requireddata in the grid. i have used 2 tables and after selecting the data the required data is displayed after executing a join query. i have wriitten code in selectindexchanged of dropdownlist box
4
2092
by: darrel | last post by:
I have a DDL list along these lines: item value="1" text="a" item value="2" text="b" item value="3" text="c" item value="2" text="d" item value="2" text="e" item value="1" text="f" item value="1" text="g"
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.