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

Refer to TableAdapter data in code?

P: n/a
I'm wanting to find the value of TableID on the current record displayed on
my form. I cannot seem to find any method within the TableAdapter class to
find this. An example I've found MS uses a bound control on the form and
then refers to the forms .text property. TableID is not displayed on the
form nor do I want it to be, so it does not have a bound control.

I've also ready that every TableAdapter has an associated DataTable class
which is actually what is populated with the data. Unfortunately I have not
been able to find a property in either class to find the value of a single
field in the current record.

Thanks,
Ryan
Jun 15 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi Ryan,

Thank you for posting.

Is the DataID a field in your DataTable?

You can get the value of any field in a datarow in a DataTable by using the
Rows collection of the DataTable. Suppose there's a DataTable named
"ClassesTable1" with two fields "ClassID" and "ClassName" in it. Then we
can get the values of the two fields in the second datarow by the following
statements:

dim var1 as Integer = ClassesTable1.Rows(1)("ClassID")
dim var2 as String = ClassesTable1.Rows(1)("ClassName")

If you have anything unclear, don't hesitate to get in touch. I look
forward to your reply.
Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Jun 16 '06 #2

P: n/a
Hi Linda,

Yes DataID is a field in the DataTable. I'm trying to refer to the
DataTable associated with a DataSet that is used to bind controls on my
form. So I would assume the syntax would be as such:

Me.myDataSet.myDataTable.Rows(<<what do I put here>>)("DataID")

What do I put to get the current record displayed on the form (the row)?

Thanks,
Ryan

"Linda Liu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:3q**************@TK2MSFTNGXA01.phx.gbl...
Hi Ryan,

Thank you for posting.

Is the DataID a field in your DataTable?

You can get the value of any field in a datarow in a DataTable by using
the
Rows collection of the DataTable. Suppose there's a DataTable named
"ClassesTable1" with two fields "ClassID" and "ClassName" in it. Then we
can get the values of the two fields in the second datarow by the
following
statements:

dim var1 as Integer = ClassesTable1.Rows(1)("ClassID")
dim var2 as String = ClassesTable1.Rows(1)("ClassName")

If you have anything unclear, don't hesitate to get in touch. I look
forward to your reply.
Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Jun 16 '06 #3

P: n/a
Well only took nearly a day to stumble across this, but here's how you do
it:
To refer to a field in the row of data currently on your form (for example
if you want to see DataID, but DataID is not bound to any form control):

Me.myDataSet.myTable.Rows(Me.myBindingSource.Posit ion)("DataID")

Whew!

"Ryan" <Ty****@newsgroups.nospam> wrote in message
news:uK**************@TK2MSFTNGP04.phx.gbl...
Hi Linda,

Yes DataID is a field in the DataTable. I'm trying to refer to the
DataTable associated with a DataSet that is used to bind controls on my
form. So I would assume the syntax would be as such:

Me.myDataSet.myDataTable.Rows(<<what do I put here>>)("DataID")

What do I put to get the current record displayed on the form (the row)?

Thanks,
Ryan

"Linda Liu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:3q**************@TK2MSFTNGXA01.phx.gbl...
Hi Ryan,

Thank you for posting.

Is the DataID a field in your DataTable?

You can get the value of any field in a datarow in a DataTable by using
the
Rows collection of the DataTable. Suppose there's a DataTable named
"ClassesTable1" with two fields "ClassID" and "ClassName" in it. Then we
can get the values of the two fields in the second datarow by the
following
statements:

dim var1 as Integer = ClassesTable1.Rows(1)("ClassID")
dim var2 as String = ClassesTable1.Rows(1)("ClassName")

If you have anything unclear, don't hesitate to get in touch. I look
forward to your reply.
Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==


Jun 16 '06 #4

P: n/a
Oh and the title of these posts are probably misleading. The TableAdapter
doesn't actually hold any data, it's just a nice tool for transferring data
back and forth from an actual database to a DataSet object. It's taken me
awile to figure out just how .NET 2.0 works.

"Ryan" <Ty****@newsgroups.nospam> wrote in message
news:em**************@TK2MSFTNGP05.phx.gbl...
Well only took nearly a day to stumble across this, but here's how you do
it:
To refer to a field in the row of data currently on your form (for example
if you want to see DataID, but DataID is not bound to any form control):

Me.myDataSet.myTable.Rows(Me.myBindingSource.Posit ion)("DataID")

Whew!

"Ryan" <Ty****@newsgroups.nospam> wrote in message
news:uK**************@TK2MSFTNGP04.phx.gbl...
Hi Linda,

Yes DataID is a field in the DataTable. I'm trying to refer to the
DataTable associated with a DataSet that is used to bind controls on my
form. So I would assume the syntax would be as such:

Me.myDataSet.myDataTable.Rows(<<what do I put here>>)("DataID")

What do I put to get the current record displayed on the form (the row)?

Thanks,
Ryan

"Linda Liu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:3q**************@TK2MSFTNGXA01.phx.gbl...
Hi Ryan,

Thank you for posting.

Is the DataID a field in your DataTable?

You can get the value of any field in a datarow in a DataTable by using
the
Rows collection of the DataTable. Suppose there's a DataTable named
"ClassesTable1" with two fields "ClassID" and "ClassName" in it. Then we
can get the values of the two fields in the second datarow by the
following
statements:

dim var1 as Integer = ClassesTable1.Rows(1)("ClassID")
dim var2 as String = ClassesTable1.Rows(1)("ClassName")

If you have anything unclear, don't hesitate to get in touch. I look
forward to your reply.
Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==



Jun 16 '06 #5

P: n/a
Hi Ryan,

Thanks for your response.

Yes, you could use the Position property of the myBindingSource to get the
position of the current datarow. You could also use the Current property of
the myBindingSource to get the current datarow directly.

For example, the statement
"((DataRowView)Me.myBindingSource.Current)("DataID ") " is equal to the
statement
"Me.myDataSet.myTable.Rows(Me.myBindingSource.Posi tion)("DataID")".

If you have any other questions, please do not hesitate to contact us. It
is always our pleasure to be of assistance.

Have a nice day!
Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Jun 19 '06 #6

P: n/a
Thanks Linda,

I was wondering about the .current property. Actually I was having some
buggy behavior with my code and once I replaced it with yours it now works
properly.

Ryan

"Linda Liu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:Px**************@TK2MSFTNGXA01.phx.gbl...
Hi Ryan,

Thanks for your response.

Yes, you could use the Position property of the myBindingSource to get the
position of the current datarow. You could also use the Current property
of
the myBindingSource to get the current datarow directly.

For example, the statement
"((DataRowView)Me.myBindingSource.Current)("DataID ") " is equal to the
statement
"Me.myDataSet.myTable.Rows(Me.myBindingSource.Posi tion)("DataID")".

If you have any other questions, please do not hesitate to contact us. It
is always our pleasure to be of assistance.

Have a nice day!
Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Jun 19 '06 #7

P: n/a
Hi Ryan,

Thank you for your response.

The Current property of the myBindingSource gets the current item in the
list. The type of the value of this property is object. To use this value,
you should cast it to a properly type. In this case, the type of the items
in the myBindingSource is DataRowView. So you should cast the value to the
type of DataRowView.

If you have any other questions, please don't hesitate to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Jun 20 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.