views:

515

answers:

2

Below is the code snippet that I am using.

using System;
using System.Collections.Generic;
using System.Text;

namespace businessTMS
{
    public class SignIn
    {
        public string authenticate(String UserName, String password)
        {  
            dataTMS.SignIn data = new dataTMS.SignIn();
          string authenticate=(string)data.authenticate(UserName, password);
            return authenticate;
        }

    }
}
+17  A: 

Your error is occurring due to this line:

string authenticate = (string)data.authenticate(UserName, password);

You are setting authenticate equal to a true/false calculation which is returning a Boolean value. Try this instead.

string authenticate = data.authenticate(UserName, password).ToString();

You can also modify the code to still return a string by doing this:

bool authenticate = data.authenticate(UserName, password);
return authenticate.ToString();

PREFERRED OPTION:
Furthermore, I'm not sure why you are returning a string representation of true/false (bool)... If it were my function, I would probably return this:

return data.authenticate(UserName, password);

I would highly encourage you to simply return the Boolean value in the PREFERRED OPTION area. There is no obvious reason to keep this in a string format.

RSolberg
copy/paste error? the lines look the same to me.
seth
@seth: yep... I corrected it.
RSolberg
+1 For advising to 'keep it simple'. :)
Guru
+1 for same reason as Guru [also nice explanation]
Zack
+2  A: 

Use the Boolean.ToString Method (documentation can be found here) like so:

using System;
using System.Collections.Generic;
using System.Text;

namespace businessTMS
{
    public class SignIn
    {
        public string authenticate(String UserName, String password)
        {  
            dataTMS.SignIn data = new dataTMS.SignIn();

            return data.authenticate(UserName, password).ToString();
        }

    }
}
Fake Code Monkey Rashid