gpt4 book ai didi

c# - 林克错误 "Input string was not in a correct format."

转载 作者:行者123 更新时间:2023-11-30 16:12:04 25 4
gpt4 key购买 nike

我的查询是这样的:

var rport = from exc in db.Exception_Datas
join emp in db.Emp_infos on exc.Emp_id equals emp.ID
where (exc.Action_date >= frm && exc.Action_date <= to) &&
emp.Branch == cmbBranch.SelectedValue &&
emp.Dept == cmbDept.SelectedValue &&
emp.ID == Convert.ToInt32(cmbEmp.SelectedValue)
select new
{
emp.Emp_name,
emp.ID,
emp.Designation,
emp.Dept,
emp.Branch,
exc.Action_date
};

我正在签订这样的 cmbEmp.Items:

var allEmp = from emp in db.Emp_infos select emp;
myItem.Text = "--Select--";
myItem.Value = "0";
cmbEmp.Items.Add(myItem);
foreach (var semp in allEmp)
{
myItem = new RadComboBoxItem();
myItem.Text = semp.Emp_name.ToString();
myItem.Value = semp.ID.ToString();
cmbEmp.Items.Add(myItem);
}

我关注了其他一些问题,并在 SO 和 SO 之外发帖。但是他们中的任何一个都没有帮助我解决问题。我收到此错误:

{"Input string was not in a correct format."} System.SystemException {System.FormatException}

最佳答案

问题似乎就在这条线上。 Convert.ToInt32(cmbEmp.SelectedValue)。确保它正确解析并在 linq 查询中使用之前解析它。像这样尝试

int empId;

if (Int32.TryParse(cmbEmp.SelectedValue, out empId))
{
var rport = from exc in db.Exception_Datas
join emp in db.Emp_infos on exc.Emp_id equals emp.ID
where (exc.Action_date >= frm && exc.Action_date <= to) &&
emp.Branch == cmbBranch.SelectedValue &&
emp.Dept == cmbDept.SelectedValue &&
emp.ID == empId
select new
{
emp.Emp_name,
emp.ID,
emp.Designation,
emp.Dept,
emp.Branch,
exc.Action_date
};
}

关于c# - 林克错误 "Input string was not in a correct format.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23498794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com