i have set combobox displaymember and valuemember.
now i want to store id in DB instead of fieldname , how?

Recommended Answers

All 2 Replies

Set the valuemember to the ID value.
Set the displaymember to the Name value.

Then use the valuemember instead of displaymember when writing the SQL to store it.

Retreive the id from the selected tiem, by using DataRowView class:

DataRowView view = comboBox1.SelectedItem as DataRowView;
int id = int.Parse(view["IdColumnName"].ToString());
//us id variable as a value to insert to db.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.