Reputation: 11197
My query looks like this:
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
};
I am contracting cmbEmp.Items like this:
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);
}
I've followed some other question and post in SO and out of SO. But any of them didn't helped me solve the problem. I am getting this error:
{"Input string was not in a correct format."} System.SystemException {System.FormatException}
Upvotes: 3
Views: 4824
Reputation: 3781
Issue seems to be on this line. Convert.ToInt32(cmbEmp.SelectedValue)
. Make sure it parsed correctly and parsed it before using in linq query. Try like this
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
};
}
Upvotes: 3