SelectedItem is a data object bound to a ComboBox data source, which in this case is equal to a DataRowView .
You need to drop the SelectedItem in the DataRowView , and then extract the corresponding value from it.
You can do it as follows:
DataRowView oDataRowView = cmbLeader.SelectedItem as DataRowView; string sValue = ""; if (oDataRowView != null) { sValue = oDataRowView.Row["YourFieldName"] as string; }
then replace (in your CommandText):
cmbLeader.SelectedItem.ToString()
from:
sValue
This will gracefully handle the case when the DataRowView is null.
YourFieldName in the above code should be the name of the field in the data source that contains the Name value. If you set this field name in the combobox DisplayMember or ValueMember , then you can simply use this property instead to save yourself some pain in the road when this field changes or when you want to reuse this code elsewhere
sValue = oDataRowView.Row[cmbLeader.DisplayMember] as string;
Alternatively, you can use cmbLeader.SelectedValue .
source share