Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 778
  • 1.1k
  • 55.2k

String not in correct format

Nov 5 2024 12:12 PM

Hello Team,

In my MVC controller I keep having this error in this code Convert.ToInt32(OrderNumber), which says that the Input string is not in correct format, and I realised it in my Sql Database table i used the data type as Varchar so I tried to re-write the code as Convert.ToString(OrderNumber).ToList() but this one to didn't work, kindly assist please.

 if (!string.IsNullOrEmpty(OrderNumber) && OrderNumber != "null")
            {           
                modifiedData = modifiedData.Where(a => a.OrderId == Convert.ToInt32(OrderNumber)).OrderBy(x => x.OrderDate).ThenBy(x => x.Qty).ToList();
            }

            if (!string.IsNullOrEmpty(sDate) && !string.IsNullOrEmpty(eDate))
            {
                DateTime fromDate = DateTime.Parse(sDate);
                DateTime toDate = DateTime.Parse(eDate);
                modifiedData = modifiedData.Where(a => DateTime.Parse(a.OrderDate) >= fromDate && DateTime.Parse(a.OrderDate) <= toDate).OrderBy(x => x.OrderDate).ThenBy(x => x.Qty).ToList();

            }

 


Answers (6)