【发布时间】:2015-04-13 14:07:47
【问题描述】:
在此表单中,用户更新客户端表中有关客户端的数据。加载表单时,它会按组合框中的值填充来自客户端表的数据的文本框。当用户更改组合框数据 int 文本框中的值时,必须更改。 但是当我试图从组合框事件中的选定值中获取客户端 ID 并将其分配给 getClientID 变量时,编译器给了我错误:
System.FormatException : 输入字符串的格式不正确。
private void ClientUpdateForm_Load(object sender, EventArgs e)
{
ClientComboBox.DataSource = AgencyContext.Client.ToList();
ClientComboBox.DisplayMember = "ClientName";
ClientComboBox.ValueMember = "ClientID";
Invalidate();
int getClientID = Convert.ToInt32(ClientComboBox.SelectedValue.ToString());
var fillTextBoxes = (from t in AgencyContext.Client where t.ClientID == getClientID select t).Single();
ClientNametextBox.Text = fillTextBoxes.ClientName;
ClientBirthtextBox.Text = fillTextBoxes.Birth.ToString(CultureInfo.CurrentCulture);
ClientPhonetextBox.Text = fillTextBoxes.Phone.ToString();
ClientPassporttextBox.Text = fillTextBoxes.Passport;
AddresstextBox.Text = fillTextBoxes.Address;
ClientStatetextBox.Text = fillTextBoxes.State;
ClientCitytextBox.Text = fillTextBoxes.City;
}
private void SaveNewClientButton_Click(object sender, EventArgs e)
{
}
private void ClientComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
var getClientID = Convert.ToInt32(ClientComboBox.SelectedValue.ToString());
var fillTextBoxes = (from t in AgencyContext.Client where t.ClientID == getClientID select t).Single();
ClientNametextBox.Text = fillTextBoxes.ClientName;
ClientBirthtextBox.Text = fillTextBoxes.Birth.ToString(CultureInfo.CurrentCulture);
ClientPhonetextBox.Text = fillTextBoxes.Phone.ToString();
ClientPassporttextBox.Text = fillTextBoxes.Passport;
AddresstextBox.Text = fillTextBoxes.Address;
ClientStatetextBox.Text = fillTextBoxes.State;
ClientCitytextBox.Text = fillTextBoxes.City;
}
【问题讨论】:
-
ClientNamesComboBox.SelectedValue.ToString()的值是多少,你的CurrentCulture是多少?在该行设置断点,调试您的代码并告诉我们。 -
值包含来自客户端表的客户端 ID。它应该是 int 类型。
-
不,不是类型。当您调试代码并用鼠标悬停
SelectedValue属性时,它就是值。 -
你是说这个{System.Data.Entity.DynamicProxies.Client_554ADCCF96234938E3C159149B78911E3A5B9F49DE47E343082953245E9D34EA}?
-
很可能 ClientNamesComboBox.SelectedValue 是空字符串结果
标签: c# winforms entity-framework combobox