natejacobs
asked on
Best way to retrieve a value from a DataRow
Does anyone have a quick way to retrieve a value from a System.Data.DataRow object?
If it were the primary key I could use the Find() method, but it's not. I have a value and I want to get the primary key for the row. I have the name of the column I'd rather not go into the ItemArray[]. Is there an easier way that I'm missing?
If it were the primary key I could use the Find() method, but it's not. I have a value and I want to get the primary key for the row. I have the name of the column I'd rather not go into the ItemArray[]. Is there an easier way that I'm missing?
ASKER
Bob -
It's the primary key that I'm looking for. I have the other value.
It's the primary key that I'm looking for. I have the other value.
You're losing me. I don't understand what you are looking for. Could you please explain more about what you would like?
I assumed that you were looking to get a value from a DataRow.
Bob
I assumed that you were looking to get a value from a DataRow.
Bob
I assume you mean that you have a datatable and you want to figure out which datarow has a column = to some value and then get the Primary Key for that row.
Use dataview
Dim dv as New DataView(datatable)
dv.Filter = "column = 'value'"
for each row as DataRow in dv.Rows
'row("primarykey")
next
Use dataview
Dim dv as New DataView(datatable)
dv.Filter = "column = 'value'"
for each row as DataRow in dv.Rows
'row("primarykey")
next
ASKER
I appreciate it, Bob.
I have a System.Data.DataTable bound to a combo box. The DataTable is called "Vendor". It has 2 columns, "VendorID" and VendorName". "VendorName" is bound to a combo box. "VendorID" is not bound to anything. When the user selects a vendor name, I need to get the VendorID.
Nate
I have a System.Data.DataTable bound to a combo box. The DataTable is called "Vendor". It has 2 columns, "VendorID" and VendorName". "VendorName" is bound to a combo box. "VendorID" is not bound to anything. When the user selects a vendor name, I need to get the VendorID.
Nate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Some days I just hate computers.
Thanks for the help.
Thanks for the help.
Dim dr As System.Data.DataRow, then you can get the value from dr("PrimaryKey").
Bob