从绑定的组合框中获取数据
本文关键字:获取 数据 组合 绑定 | 更新日期: 2023-09-27 18:02:39
在获取数据库绑定的组合框值时遇到问题
`String stri = "Select [Interest] from tbl_Interests";
SqlCommand command = new SqlCommand(stri, con);
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds,"tbl_Interests");
cmbTypeofList.DataSource = ds.Tables["tbl_Interests"];
cmbTypeofList.ValueMember = "Interest";`
调用它string intr = cmbTypeofList.SelectedItem.ToString();
string intr = cmbTypeofList.SelectedValue.ToString();
在上述两个条件中,我获得的选择值为System.Data.DataRowView
string intr = cmbTypeofList.SelectedText;
如果我用上面的方法,我得到的是空值
如何在c# windowsapp中获取组合框的选定值
设置组合框的显示成员和值成员为适当的字段名看看这个链接如何为组合框项设置值