数据表获取值成员数据 [英] Datatables getting the value member data
问题描述
你好
希望一切都很好.
我们有一个小型应用程序,可以在其中将SQL中的数据从dt检索到组合框.我们得到了值成员和显示成员,显示成员显示了正确的格式.但是,值成员应该是一个保存用户ID的int.
We got a small application where we retrieve data from SQL into a dt into comboboxes. we got the value member and the dispaly member, display member is showing the correct format. But the value member is suppose to be a int which hold the user id.
问题是,当我们执行以下操作时,它会将值成员显示为具有字段名称而不是值的字符串.
The problem is when we do the following it shows the value member as a string with the field name and not the value.
正在寻找combox.ValueMember.Value之类的东西.
Looking for something like combox.ValueMember.Value.
private void ToDoPriorityInterface_Load(object sender, EventArgs e)
{
DataTable dl = new DataTable();
dl = GetCompboxDet();
// Populate the Responsible Person Combobox
comRespons.DataSource = dl;
comRespons.DisplayMember = "EmpName";
comRespons.ValueMember = "StaffID";
DataTable d2 = new DataTable();
d2 = GetCompboxDet();
comResReq.DataSource = d2;
comResReq.DisplayMember = "EmpName";
comResReq.ValueMember = "StaffID";
}
private void SetVariables()
{
Deadline = dtPicker.Value;
TaskDescri = txtDescrip.ToString();
TaskComment = txtComment.ToString();
ResourceRequired = Int32.Parse(comResReq.ValueMember);
AllocatedTo = Int32.Parse(comRespons.ValueMember);
Status = 1;
Completion = 0;
}
labjac
推荐答案
对不起
愚蠢的错误,长达许多漫长的夜晚.
Stupid mistake, to many long nights.
ResourceRequired = Int32.Parse(comResReq.SelectedValue);
ResourceRequired = Int32.Parse(comResReq.SelectedValue);
此致
这篇关于数据表获取值成员数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!