Hi I am trying to get information from two tables in the database but it gives an argument exception saying "Column 'SubContratorID' does not belong to table .”

Which 'SubContratorID' is it referring to …??

String query = @"Select ps.PSubContractID,s.SubContractorID,s.FirstName,s.LastName,s.Position,s.Email,s.TelNo,s.Agency From PSubContract as ps, SubContractor as s Where  ps.ID=@id and ps.Phase=@phase and ps.SubContractorID=s.SubContractorID";

silly mistake

Hi I am trying to get information from two tables in the database but it gives an argument exception saying "Column 'SubContratorID' does not belong to table .”

Which 'SubContratorID' is it referring to …??

String query = @"Select ps.PSubContractID,s.SubContractorID,s.FirstName,s.LastName,s.Position,s.Email,s.TelNo,s.Agency From PSubContract as ps, SubContractor as s Where  ps.ID=@id and ps.Phase=@phase and ps.SubContractorID=s.SubContractorID";

silly mistake

Still learning C# myself ... but I've been a programmer for over 30 years. The way I would resolve this error is to rebuild the query in stages.

Example ... run the query without the WHERE qualifiers ... if it doesn't whine then you know which portion of the statement its having problems with.

Something else to try, is to build the query statement in SQL itself ... doing that might reveal immediately what the problem is ... and if it doesn't, it may be more detailed in its explanation (when you run it) what the problem is.

Just some suggestions to get you going. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.