C# .NET - unable to cast object of type 'System.Decimal' to type 'System.String'

Asked By avula on 30-Oct-13 03:15 PM

Hi Every one,

Am getting  this error in live server only, which is working in our local server and also in other server , but not working in live server.

Can you please suggest
Robbe Morris replied to avula on 30-Oct-13 03:49 PM
It is right there in position 13 of the code you posted for us to review.  I can see what you did wrong quite clearly.

avula replied to Robbe Morris on 30-Oct-13 03:59 PM
 Hi Every one,

 private List<domain_EmpLists> EmpListsArray(string CustomerId)
    
{

 var EmpLists = (from p in dataContext.vwEmailList
         where p.emp_id.Equals(CustomerId)
         select p).ToList();

  //etc...

}
 email_id is decimal in vwEmailList..

Can you please suggest me..


Robbe Morris replied to avula on 30-Oct-13 04:01 PM
If p.email_id is a decimal, then the input parameter to the method EmpListsArray should be a decimal not a string.  Or, you convert CustomerId to a decimal before performing the "Equals" comparison on it.

Also, are you sure the property value types for domain_EmpLists all match the property data types returned in "p"?
avula replied to Robbe Morris on 30-Oct-13 04:30 PM
Hi ,
Here is the final code of mine.

private List<domain_adds> GetEmpArray(string empId)
    {
      domainContext = new EmpDomainContext();
      
      List<domain_adds> lstdomainAddress = new List<domain_adds>();
      domain_adds empAddress = null;

    
      var empAddresses = (from p in domainContext.vwEmpList
         where p.empId.Equals(empId)
         select p).ToList();

      foreach (var adr in empAddresses)
      {
       
      empAddress = new domain_adds()
      {
        _address_1_id = adr.id,
        _address_1_name = adr.name
      };
      lstdomainAddress.Add(empAddress);
      }
      return lstdomainAddress;
    }

Can you please suggest . above code is working fine in local but  not working in live server

please suggest me..