In your
Where
clause,
CollectorId
and
conpersonid
were not preceded by either
a.
or
b.
table alias. In the example below, I preceded them by
a.
table alias.
SqlDataAdapter adp = new SqlDataAdapter("SELECT a.Collectorid, a.Title, a.Surname, a.Firstname, a.Middlename, a.Gender, a.Dateofbirth, a.Nationality, a.Religion, a.Maritalstatus, a.Spousename, a.Telephone, a.Postaladdress, a.Residentialaddress, a.Hometownaddress from tblCollectorsRegistration a JOIN tblCollectorscontactperson b ON (a.Collectorid = b.Collectorid) WHERE a.Collectorid = '" + this.txtCollectorid.Text + "' AND a.conpersonid = (SELECT MIN(conpersonid) FROM tblCollectorscontactperson)", conn);
Also, by using the parameter
this.txtCollectorid.Text
in a concatenated string, you leave your application open to
SQL Injection Attack. All parameters should be passed using the
SQLParameter
Class. Using
SQLParameter
Class also improves performance.