Your query should be something like :
string str = " Select Address,PhoneNo from AddressInfo A,PhoneInfo P where A.Contactid = P.Contactid and A.Contactid=(Select Contactid from ContactInfo where Fid=(Select Fid from Farmers where Name='" + txtUpName.Text + "'));";