|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Refer to TableAdapter data in code?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 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. ==================================================== 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 Show quoteHide quote "Linda Liu [MSFT]" <v-l***@online.microsoft.com> wrote in message news:3qCeH9SkGHA.4948@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. > ==================================================== > 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.Position)("DataID") Whew! Show quoteHide quote "Ryan" <Tyveil@newsgroups.nospam> wrote in message news:uK79CPUkGHA.1508@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-l***@online.microsoft.com> wrote in message > news:3qCeH9SkGHA.4948@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. >> ==================================================== >> > > 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. Show quoteHide quote "Ryan" <Tyveil@newsgroups.nospam> wrote in message news:emkB4BYkGHA.3536@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.Position)("DataID") > > Whew! > > "Ryan" <Tyveil@newsgroups.nospam> wrote in message > news:uK79CPUkGHA.1508@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-l***@online.microsoft.com> wrote in message >> news:3qCeH9SkGHA.4948@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. >>> ==================================================== >>> >> >> > > 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.Position)("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. ==================================================== 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 Show quoteHide quote "Linda Liu [MSFT]" <v-l***@online.microsoft.com> wrote in message news:PxDOGx3kGHA.5184@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.Position)("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. > ==================================================== > 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. ====================================================
Expose Form Properties and it Controls Properties.
How to Send an SMS URI IsFile Streaming a file to text? VB.net 2005 splash screen Parameter description List Box Population How to get Windows XP Edition? Updating a DataSet while using DataGridView writing a text in a file in vb.net not working properly |
|||||||||||||||||||||||