Using bitwise to create a multiple selection listbox and having it bound to a sql

J

Jay Ruyle

I'm trying to figure out a way to list several items in a listbox and let
the user select any number of items in the listbox. I have tried to code in
the items as bitwise items but all it stores in the database is the top item
in the listbox.

How can I get the listbox to add all the bit values to be stored and also
come out properly when viewed later?


Example:

SQL Table = Valid Phases Lookup
Name Bitwise
Phase-10 1
Phase-20 2
Phase-30 4
Phase-40 8
Phase-60 16
Phase-70 32


SQL Table = Projects
Name Stored Type
ProjectName nvarchar
ValidPhases bigint (using listbox in c# with values
bound to lookup table above)
....Otherstuff...


Other notes:
I do have "MultiExtended" as the Selection Mode.
ValueMode to use the bitwise value.

Just having trouble getting the bitwise values to add up in the program and
send the correct value to the database.

Ive attempted a custom listbox and combo-box. Please help.

Jay
 
R

Rad

I'm trying to figure out a way to list several items in a listbox and let
the user select any number of items in the listbox. I have tried to code in
the items as bitwise items but all it stores in the database is the top item
in the listbox.

How can I get the listbox to add all the bit values to be stored and also
come out properly when viewed later?


Example:

SQL Table = Valid Phases Lookup
Name Bitwise
Phase-10 1
Phase-20 2
Phase-30 4
Phase-40 8
Phase-60 16
Phase-70 32


SQL Table = Projects
Name Stored Type
ProjectName nvarchar
ValidPhases bigint (using listbox in c# with values
bound to lookup table above)
...Otherstuff...


Other notes:
I do have "MultiExtended" as the Selection Mode.
ValueMode to use the bitwise value.

Just having trouble getting the bitwise values to add up in the program and
send the correct value to the database.

Ive attempted a custom listbox and combo-box. Please help.

Jay

There's a difference between the storage of datetime values in the
..NET framework and SQL Server. Read these articles for some details of
the difference and some possible workarous:

http://www.velocityreviews.com/forums/t111968-datetime-problem.html

http://www.eggheadcafe.com/articles/20021111.asp

http://blogs.wdevs.com/angelos/archive/2005/06/02/3660.aspx
 
R

Rad

There's a difference between the storage of datetime values in the
.NET framework and SQL Server. Read these articles for some details of
the difference and some possible workarous:

http://www.velocityreviews.com/forums/t111968-datetime-problem.html

http://www.eggheadcafe.com/articles/20021111.asp

http://blogs.wdevs.com/angelos/archive/2005/06/02/3660.aspx

Sorry, mixed up my Agent windows :(

But since I am here anyway, I might as well chip in.

First of all, If I understand your architecture. If someone selects
Phase 10 and Phase 20, I am you store 3 in the database.

If this is the case I'm not sure you can databind directly.

You might have to loop through your listbox items to manually select
the valid phases.

Random question ... How do you handle queries with this design? How
can I retrieve all items at Phase 10 and Phase 20?
 
J

Jay Ruyle

Rad said:
Sorry, mixed up my Agent windows :(

But since I am here anyway, I might as well chip in.

First of all, If I understand your architecture. If someone selects
Phase 10 and Phase 20, I am you store 3 in the database.

If this is the case I'm not sure you can databind directly.

You might have to loop through your listbox items to manually select
the valid phases.

Random question ... How do you handle queries with this design? How
can I retrieve all items at Phase 10 and Phase 20?

Correct you would store 3 in the database.

I did make it unbound , but when I grab the value from the listbox it
returns the value of the top item and not a collection of items or tally of
the bit items.

Random answer: Bitwise calculation.

0 = 00000000

1 = 00000001

2 = 00000010

3 = 00000011

4 = 00000100

5 = 00000101

You can use a bitwise calculation to determine which bits are turned on and
off.


Article that talks about the advantage of using bitwise data in a database.
http://www.sqlservercentral.com/columnists/hroggero/usingbitmaskoperators.asp

Jay
 

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

Top