Moving table field name to variable name in VB.NET

A

adiel_g

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
 
A

adiel_g

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
 

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