none
Error: Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>' RRS feed

  • Question

  • Hi,

    Why I am getting:

    Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>'

    For below code:

    private Task<string> GetPasswordSalt()
    {
        sql_connection = new SqlConnection("Server=my.domain.com; Database=myDB; User Id=sa; Password=myPassword;");
        sql_connection.Open();
    
        sql_command = new SqlCommand("sp_get_password_salt", sql_connection);
        sql_command.CommandType = CommandType.StoredProcedure;
        sql_command.Parameters.Add(new SqlParameter("@email", TextBoxSigninEmailAddress.Text));
        SqlDataReader sql_reader = sql_command.ExecuteReader();
    
        ObservableCollection<object> trends = new ObservableCollection<object>();
    
        if (sql_reader.HasRows)
        {
            while (sql_reader.Read())
            {
                password_salt = Convert.ToString(sql_reader["password_salt"]);
            }
        }
        else
        {
            password_salt = "X";
        }
    
        return password_salt;
    }
    
    


    Thanks,

    Jassim

    Wednesday, June 26, 2019 2:08 PM

Answers

  • Try add async keyword:

    private async Task<string> GetPasswordSalt()

    If you don't need async, just change the return type to string instead.

    private string GetPasswordSalt()
    Thursday, June 27, 2019 1:17 AM
    Answerer

All replies

  • Try add async keyword:

    private async Task<string> GetPasswordSalt()

    If you don't need async, just change the return type to string instead.

    private string GetPasswordSalt()
    Thursday, June 27, 2019 1:17 AM
    Answerer
  • Thank you @cheong00.  Your suggestion with using async trigger my looking at my code and found that I needed to use "await" which helped me with my scenario.  Thank you very much!!

    Tien Le

    Tuesday, October 15, 2019 3:55 AM