datarow variable can't be returned from a try/catch statement

Viewed 22

I am creating a section of a system, the user will input their ID and password to log in with. If the password doesn't match the id a label is displayed. the piece I am trying to work on is if the ID is not found then the system will spit out a label saying that the id isn't found

 private void login_Click(object sender, EventArgs e)
    {
        DataSet2.STAFFRow RESULT;//Creates variable result in the datatype of the dataset row?
        try//tries to search the dataset for the id 
        {
            
            RESULT = dataSet2.STAFF.FindBySTAFF_ID(int.Parse((staff_ID).Text));
            return RESULT[11.ToString()];//this should return the Result variable so it can be used later
        }
        catch
        {//if the search fails ( no ID found) then information is passed to the user
            result.Text = "There is no account with this ID present";
            result.Visible = true;
        }
        
            
            
            
            
            
        if ((password.Text) != RESULT[11].ToString())// this section needs the data from RESULT to check if passwords match
        {
            result.Text = "The ID and Password do not match ";
            result.Visible = true;
        }
        else
        {
            result.ForeColor = Color.Green;
            result.Text = "The ID and Password match";
            result.Visible = true;
        }

    }

TLDR in order to get the RESULT out of the loop I tried to use return, for some reason the editor gives me the error CS0127

0 Answers
Related