473,406 Members | 2,769 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,406 software developers and data experts.

Moving table field name to variable name in VB.NET

Hello everyone, I am trying to move a field name to a variable in
vb.net. For example, first I retrieve the record from the database
and save its value:

....
userGroup =
ds.Tables("Default").Rows(x).Item("UserGroupAccess ").ToString
'retrive access value from dataset
....

Then, depending on the value retrieved I want to setup a specific
boolean variable to True:

....
objUserAccess.[userGroup] = True
....

In this case the table might contain records such as this:

UserName Access
======== =======
Bob Admin
John User

And the objUserAccess contains variables such as this

admin as boolean
user as boolean

In the example above, if the value of the table field UserGroupAccess
is equal to Admin, then
it should basically set admin to true. If we were to manually do this
it would be set by this statement:

....
objUserAccess.Admin = True
....

But instead of the above statement, It would be automated depending on
the value pulled from the database:

....
objUserAccess.[userGroup] = True
....

I would appreciate any help on finding the best way to accomplish
this.

Thanks Before Hand,
Adiel
Jun 27 '08 #1
3 2967
Looks like you are looking for properties (basically they seem to be a
"variable" but changing/reading the value runs some code to update/retrieve
this value).

Try http://msdn.microsoft.com/en-us/libr...77(VS.71).aspx

By using properties your class could load a user and make available several
boolean properties based on the underlying values read from the db...

I would also recommend reading the whole spec at least once so that you have
at least an overviw of what you have at your disposal...

--
Patrice

<ad*****@hotmail.coma écrit dans le message de groupe de discussion :
b6**********************************...oglegroups.com...
Hello everyone, I am trying to move a field name to a variable in
vb.net. For example, first I retrieve the record from the database
and save its value:

...
userGroup =
ds.Tables("Default").Rows(x).Item("UserGroupAccess ").ToString
'retrive access value from dataset
...

Then, depending on the value retrieved I want to setup a specific
boolean variable to True:

...
objUserAccess.[userGroup] = True
...

In this case the table might contain records such as this:

UserName Access
======== =======
Bob Admin
John User

And the objUserAccess contains variables such as this

admin as boolean
user as boolean

In the example above, if the value of the table field UserGroupAccess
is equal to Admin, then
it should basically set admin to true. If we were to manually do this
it would be set by this statement:

...
objUserAccess.Admin = True
...

But instead of the above statement, It would be automated depending on
the value pulled from the database:

...
objUserAccess.[userGroup] = True
...

I would appreciate any help on finding the best way to accomplish
this.

Thanks Before Hand,
Adiel

Jun 27 '08 #2
Patrice, thanks for your reply. Yes, I am familiar with properties
for classes. But, that is not what I am trying to accomplish. I have
a field in a table depending on the value of that field I am going to
set a specific boolean variable to True. Take a look at the following
table:

In this case the table might contain records such as this:
UserName Access
======== =======
Bob Admin
John User

The table contains the value of Admin for the user Bob. So if I run a
query against this table such as:

select * from tblUserAccess where UserName = 'Bob'

The values returned would be:

UserName UserGroupAccess
======== =======
Bob Admin

Now that I have this record, I extract the access level with the
following statement:

....
userGroup =
ds.Tables("Default").Rows(0).Item("UserGroupAccess ").ToString
'retrive access value from dataset
....

Now the field name called userGroup contains the value "Admin"
Now I have a class called clsUserAccess as follows:

Public Class clsUserAccess
public Admin as boolean
public User as boolean
' for this example, the class uses two public variables with no
properties
End Class
Now comes my question, I want to move the table field name to a
variable name as follows:

' Instantiate the class
dim objUserAccess as new clsUserAccess
' Set the Admin variable to true
objUserAccess.[userGroup] = True ' <-- This is the statement I am
looking for, does it exist?
Of course the above statement does not exist but I am looking for its
equivalent. I am hoping to
find a way to do this instead of having to loop through each item such
as:

If userGroup = "Admin" then
objUserAccess.Admin = True ' manually setting admin flag to true
elseif userGroup = "User" then
objUserAccess.User = True ' manually setting user flag to true
....
end if

Thanks Before Hand,
Adiel

Jun 27 '08 #3
Ah ok... This time I believe you are looking CallByName :
http://msdn.microsoft.com/fr-fr/libr...x6(VS.80).aspx
(which basically wraps capabilities found inside System.Reflection).
Hopefully I should have finally understood how you want to handle this...

--
Patrice
<ad*****@hotmail.coma écrit dans le message de groupe de discussion :
db**********************************...oglegroups.com...
Patrice, thanks for your reply. Yes, I am familiar with properties
for classes. But, that is not what I am trying to accomplish. I have
a field in a table depending on the value of that field I am going to
set a specific boolean variable to True. Take a look at the following
table:

In this case the table might contain records such as this:
UserName Access
======== =======
Bob Admin
John User

The table contains the value of Admin for the user Bob. So if I run a
query against this table such as:

select * from tblUserAccess where UserName = 'Bob'

The values returned would be:

UserName UserGroupAccess
======== =======
Bob Admin

Now that I have this record, I extract the access level with the
following statement:

...
userGroup =
ds.Tables("Default").Rows(0).Item("UserGroupAccess ").ToString
'retrive access value from dataset
...

Now the field name called userGroup contains the value "Admin"
Now I have a class called clsUserAccess as follows:

Public Class clsUserAccess
public Admin as boolean
public User as boolean
' for this example, the class uses two public variables with no
properties
End Class
Now comes my question, I want to move the table field name to a
variable name as follows:

' Instantiate the class
dim objUserAccess as new clsUserAccess
' Set the Admin variable to true
objUserAccess.[userGroup] = True ' <-- This is the statement I am
looking for, does it exist?
Of course the above statement does not exist but I am looking for its
equivalent. I am hoping to
find a way to do this instead of having to loop through each item such
as:

If userGroup = "Admin" then
objUserAccess.Admin = True ' manually setting admin flag to true
elseif userGroup = "User" then
objUserAccess.User = True ' manually setting user flag to true
...
end if

Thanks Before Hand,
Adiel


Jun 27 '08 #4

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

Similar topics

16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
5
by: devx777 | last post by:
Hello, I am trying to find some information or an example on how to build a dynamic query in DB2 that would allow me to join a table which its name is stored as a field value on another table....
9
by: john | last post by:
I have imported an Excel spreadsheet in Access. This table has 150 fields. The first field is 'user name', and all the other fields represent application names of which the value can be True of...
1
by: SyddyS | last post by:
Hi all, please help ASAP! Well, it's been a long and bumpy ride, but my little Access DB is finally graduating and moving out of the house. My homebrewed contact and sales database is being...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
3
prn
by: prn | last post by:
Hi folks, I've got something that's driving me crazy here. If you don't want to read a long explanation, this is not the post for you. My problematic Access app is a DB for keeping track of...
5
by: quirk | last post by:
I am trying to write a script where a page is populated with some maths questions, user answers them (it's timed but I've left this bit out), gets results on same page and ajax takes their score,...
0
by: timber910 | last post by:
Ok, I have a button on a form that I'm using to create another table I will need later in my form. I have created a reference table called Ref_Table (holds my table names - using this as the tables...
5
by: timber910 | last post by:
I posted this in the VB forum but I think its in the wrong place. So I thought I would try here. _________________________________________ Ok, I have a button on a form that I'm using to create...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.