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

Select Value From Specific Table Column in TableAdapter

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
3 18753
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tom Urbanowicz | last post by:
I have a table with 100+ columns, for which I'm trying to retrieve only 1 specific record. For this single record, I do not know which of the columns are NULL, and which are populated. I would...
8
by: Adam Nemitoff | last post by:
Is is possible to construct a SELECT statement that contains a WHERE clause that uses the value from a column in the "next" row? ie. given a table with a single field named "myField" with the...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
3
by: dumbledad | last post by:
Hi All, I'm confused by how to replace a SELECT statement in a SQL statement with a specific value. The table I'm working on is a list of words (a column called "word") with an index int...
5
by: Han Lim | last post by:
Dear All, I have an application written by VB.Net with connect to a Microsoft Access database. One of the forms is to select data using oleAdapter and fill it into a dataset. In the oleAdapter, i...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
13
by: roberto | last post by:
I have this kind of information on a db table COMPANY USER MYDATA ______________________________ AA 01 AA01 USER AAUS 01 USER AA01US BB
5
by: Mahesh S | last post by:
Hi I would like to write a SQL select statement that would fetch rows numbered 50 to 100. Let me clarify, if i say "fetch first 10 rows only", it returns the first 10 rows from the resultset....
4
tjc0ol
by: tjc0ol | last post by:
Hi guys, I'm a newbie in php and I got error in my index.php which is: 1054 - Unknown column 'p.products_id' in 'on clause' select p.products_image, pd.products_name, p.products_id,...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.