Question Obtain value from dataset based on other column's value

CCrawshaw

Member
Joined
May 19, 2011
Messages
8
Programming Experience
Beginner
I have a combo box which is populated from a dataset (pulling values from the column Actuator_ID). When an item is selected from the combobox, I need to return another value from the dataset (column Gateway_Channel).

In the 'selectedindexchanged' sub, I have the following line which should return the value from the second field (gateway_channel) but whatever item is selected in the combobox, only the value from the first row is returned and I can't figure out why!

VB.NET:
errBox.AppendText((ds.Tables("Actuators").Rows("Actuator_ID" = ComboBox3.SelectedItem.substring(0, 2)).Item("Gateway_Channel")).ToString

Cheers,
Chris
 
Turning your code into english:

errBox.AppendText((ds.Tables("Actuators").Rows("Actuator_ID" = ComboBox3.SelectedItem.substring(0, 2)).Item("Gateway_Channel")).ToString

Compare the string "Actuator_ID" for being equal to the first 2 characters of the SelectedItem of Combo3 [generates FALSE, "Actuator_ID" can never equal any string of length 2
Use the generated FALSE boolean as a row indexer (i'm surprised VB allows conversion from bool to int?) to the actuators table retrieving whatever row is specified by FALSE
In the retrieved row, return the Gateway_Channel column, turn it to a string
APpend the returned string to the errBox

Is this what you intended your code to do?
 
Back
Top