Retrieving data from a combobox binded to a dataset

djohnston

Active member
Joined
Jun 1, 2006
Messages
33
Programming Experience
Beginner
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'TODO: This line of code loads data into the 'IDM_Test_1000007680DataSet1.vw_BankCustomerRelationship' table. You can move, or remove it, as needed.

Me.Vw_relationshipTableAdapter1.Fill
(Me.dataset2.vw_relationship)

Friend WithEvents DataSet1 As
Fedline.DataSet1
Friend WithEvents VwCustomerRelationshipBindingSource1 As System.Windows.Forms.BindingSource
Friend WithEvents Vw_CustomerRelationshipTableAdapter1 As Fedline.TableAdapters.vw_CustomerRelationshipTableAdapter


Ok so there is the sample code, Basically I have a dataset and i need to pull variables out of the dataset. I need some example code on pulling data out of a dataset so i can then pass it to the database. I am also selecting a certain row of data by using a combobox and diosplaying one variable from the dataset say bank name. After i select the correct bank name I then need get the BankRouting number and 4 other variables from that dataset how would I pull that data.
David
 
Assign the DataSet to the BindingSource's DataSource property. Assign the name of the DataTable to the BindingSource's DataMember property. Assign the BindingSource to the DataSource property of the ComboBox. Assign the name of the column you wish to display data from to the DisplayMember property of the ComboBox.

Now, when the user makes a selection in the ComboBox, the Current property of the BindingSource will be a reference to a DataRowView object for the selected row. You can get all the field values from that.

E.g.
VB.NET:
myBindingSource.DataSource = myDataSet
myBindingSource.DataMember = "MyTable" 'Name of table.

myComboBox.DisplayMember = "Name" 'Name of column.
myComboBox.ValueMember = "ID" 'Name of column.
myComboBox.DataSource = myBindingSource

Dim myRow As DataRowView = DirectCast(myBindingSource.Current, DataRowView)

'Show the value from the Description column from the row chosen by name in the ComboBox.
MessageBox.Show(myRow("Description"))
 
Back
Top