By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,245 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,245 IT Pros & Developers. It's quick & easy.

Select Value From Specific Table Column in TableAdapter

P: n/a
I'm not really sure how to ask this question because I'm still getting my
feet wet with data access and VB.NET, but here goes:

To start off with, I'm using VB 2005 Express to connect to an Access database.

I have a dataset in which a parameterized query returns the correct result
set in the forms of a tableadapter and a bindingnavigator. In other words, I
can perform my query and see that the tableadapter and bindingnavigator
contain the row(s) of data I expect.

What I want to do is make a decision in my program based on the value in one
of the columns in the tableadapter or bindingnavigator. Here's a short
example:

In my tableadapter and bindingnavigator, I can see the following columns and
values after running my query:
id = 2
partnumber = 12345
itemtype = OPT

Before I display a certain form, I want to know what the value of the
"itemtype" column is so I can customize the information on the form. So, in
pseudocode, I want to do:

If itemtype = 'OPT' Then
aControl.Enabled = TRUE
Else
aControl.Enabled = FALSE
End If

Where I'm stuck is the If itemtype = 'OPT'. How in the world do I find out
what the value is in that column in my tableadapter or bindingnavigator or am
I barking up the entirely wrong tree here?

Thanks in advance for any assistance.

Rich

Apr 4 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
OK, so, after a day of poking around for different ways to ask this question
and looking for answers in dozens of places, I finally found one site that
got me on the right track. Do I remember it? No, and the URL is on my work PC
so all I have to offer is my solution.

In the class where I wanted to make my programming decision, I created an
instance of the DataTable object and an instance of the DataRowCollection
object:

Protected dt As DataTable
Protected dr As DataRowCollection

Then I grabbed the table I wanted then its row collection:

Me.dt = ProductsDataSet.Tables("N_Options") 'The table I want
Me.dr = dt.Rows() 'The table's row collection

Once I had the collection of rows in the table (because of the nature of the
query, I know it _should_ only be a single row), I was able to get the value
of the column I was interested in:

Dim myOType As String
myOType = Me.dr.Item(0).Item("O_Type").ToString()

Now that I have myOType, I can make whatever programming decisions need to
be made.

Is this the "correct" way to do it? I don't know. But I know it works and
that it allows me to do what I need to do programmatically. So if you're
stuck in the same kind of situation I was, hopefully this will help you out
in much less time and with much less frustration than I invested.

Rich
"Rich Hutchins" wrote:
I'm not really sure how to ask this question because I'm still getting my
feet wet with data access and VB.NET, but here goes:

To start off with, I'm using VB 2005 Express to connect to an Access database.

I have a dataset in which a parameterized query returns the correct result
set in the forms of a tableadapter and a bindingnavigator. In other words, I
can perform my query and see that the tableadapter and bindingnavigator
contain the row(s) of data I expect.

What I want to do is make a decision in my program based on the value in one
of the columns in the tableadapter or bindingnavigator. Here's a short
example:

In my tableadapter and bindingnavigator, I can see the following columns and
values after running my query:
id = 2
partnumber = 12345
itemtype = OPT

Before I display a certain form, I want to know what the value of the
"itemtype" column is so I can customize the information on the form. So, in
pseudocode, I want to do:

If itemtype = 'OPT' Then
aControl.Enabled = TRUE
Else
aControl.Enabled = FALSE
End If

Where I'm stuck is the If itemtype = 'OPT'. How in the world do I find out
what the value is in that column in my tableadapter or bindingnavigator or am
I barking up the entirely wrong tree here?

Thanks in advance for any assistance.

Rich
Apr 5 '07 #2

P: n/a
Rich,

A TableAdapter holds no data, it adapts data in a datatable.

A datatable is a part of a dataset (there are more datatables in a dataset).
However in connection with a tableAdapter there is just one. (With the
dataset it is the dataAdapter)

The TableAdapter creates strongly typed datasets. However all datasets can
be used non strongly typed.

Let us see what the dataset looks like.
It holds as I wrote already datatables
It holds as well relations between those tables.
Tables holds
Columns which describes the items and
Rows which hold the items.

Therefore the first item in a dataset is
ds.tables(0).Rows(0).Item(0)

The last is
ds.tables(ds.tables.count -1).Rows(etc......................

In a strongly typed dataset the first item is (I often write this wrong so
check this one)
ds.MyTableRow(0).myItem

Cor

"Rich Hutchins" <Ri**********@discussions.microsoft.comschreef in bericht
news:DA**********************************@microsof t.com...
OK, so, after a day of poking around for different ways to ask this
question
and looking for answers in dozens of places, I finally found one site that
got me on the right track. Do I remember it? No, and the URL is on my work
PC
so all I have to offer is my solution.

In the class where I wanted to make my programming decision, I created an
instance of the DataTable object and an instance of the DataRowCollection
object:

Protected dt As DataTable
Protected dr As DataRowCollection

Then I grabbed the table I wanted then its row collection:

Me.dt = ProductsDataSet.Tables("N_Options") 'The table I want
Me.dr = dt.Rows() 'The table's row collection

Once I had the collection of rows in the table (because of the nature of
the
query, I know it _should_ only be a single row), I was able to get the
value
of the column I was interested in:

Dim myOType As String
myOType = Me.dr.Item(0).Item("O_Type").ToString()

Now that I have myOType, I can make whatever programming decisions need to
be made.

Is this the "correct" way to do it? I don't know. But I know it works and
that it allows me to do what I need to do programmatically. So if you're
stuck in the same kind of situation I was, hopefully this will help you
out
in much less time and with much less frustration than I invested.

Rich
"Rich Hutchins" wrote:
>I'm not really sure how to ask this question because I'm still getting my
feet wet with data access and VB.NET, but here goes:

To start off with, I'm using VB 2005 Express to connect to an Access
database.

I have a dataset in which a parameterized query returns the correct
result
set in the forms of a tableadapter and a bindingnavigator. In other
words, I
can perform my query and see that the tableadapter and bindingnavigator
contain the row(s) of data I expect.

What I want to do is make a decision in my program based on the value in
one
of the columns in the tableadapter or bindingnavigator. Here's a short
example:

In my tableadapter and bindingnavigator, I can see the following columns
and
values after running my query:
id = 2
partnumber = 12345
itemtype = OPT

Before I display a certain form, I want to know what the value of the
"itemtype" column is so I can customize the information on the form. So,
in
pseudocode, I want to do:

If itemtype = 'OPT' Then
aControl.Enabled = TRUE
Else
aControl.Enabled = FALSE
End If

Where I'm stuck is the If itemtype = 'OPT'. How in the world do I find
out
what the value is in that column in my tableadapter or bindingnavigator
or am
I barking up the entirely wrong tree here?

Thanks in advance for any assistance.

Rich

Apr 5 '07 #3

P: n/a
Cor,

Thanks for your response. You've given me a much more straightforward (and
probably closer to "standard practice") way to access the information I want.
Instead of creating DataTable and DataRowCollection objects (which end up
being redundant with the existing dataset), I can get the value of the column
I want by doing this (for example):

MessageBox.Show(ProductsDataSet.Tables("N_Products ").Rows(N_ProductsBindingSource.Position()).Item(" N_Description"))

Rich
Apr 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.