本文介绍了如何获得与组合框选定索引关联的主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有自动递增主键的数据库.我的组合框按字母顺序显示名称列表.我可以获取索引,但是我对如何获取主键感到困惑.
I have a database with a primary key that''s automatically incremented. My Combo Box displays a list of names in alphabetical order. I can get the index but I''m stuck on how to get the primary key.
private void cmdEdit_Click(object sender, EventArgs e)
{
string strField = this.cboClients.ValueMember;
int intClient = this.cboClients.SelectedIndex;
}
预先感谢您的帮助.
Thanks in advance for your help.
推荐答案
//bind combo box like this...
this.cboClients.DataSource = ds.Tables["tableName"]; // for that you need to fire a select query that fill the record in dataset
this.cboClients.DisplayMember = "FieldName"; // give the name of field that you want to display in combo box
this.cboClients.ValueMember = "FieldName"; // give the name of primary field...
private void cmdEdit_Click(object sender, EventArgs e)
{
string strField = this.cboClients.ValueMember;
int intClient = this.cboClients.SelectedValue;
}
这篇关于如何获得与组合框选定索引关联的主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!