SQL to LINQ conversion

  • Thread starter Thread starter MRM256
  • Start date Start date
M

MRM256

Guest
I have this SQL Statement:

SELECT tblEmployees.EmpID, tblEmployees.EmpName, tblPositions.PositionName, tblTeams.TeamName
FROM tblTeams RIGHT JOIN (tblEmployees INNER JOIN tblPositions ON tblEmployees.EmpID = tblPositions.AssignedEmployeeID) ON tblTeams.TeamID = tblPositions.AssignedTeamID
WHERE ((Not (tblEmployees.EmpID) = [lngID]));

Here is the LINQ version(I think)

Dim query = From Team In dtTeams
Join Emp In dtEmp
Join Pos In dtPostion
On Emp.Field(Of String)("EmpID") Equals Pos.Field(Of String)("AssignedEmployee")
On Team.Field(Of String)("TeamID") Equals Pos.Field(Of String)("AssignedTeam")
Where ((Not (Emp.Field(Of String)("EmpID") = strEmpID)))
Select
{
EmployeeID = Emp.Field(Of String)("EmpID"), _
EmployeeName = Emp.Field(Of String)("EmpName"), _
PositionName = Pos.Field(Of String)("PositionName"), _
TeamName = Team.Field(Of String)("TeamName")
}
For Each q In query
Debug.Print("EmployeeID = " & EmployeeID & vbCrLf & _
"EmployeeName = " & EmployeeName & vbCrLf & _
"PositionName = " & PositionName & vbCrLf & _
"TeamName = " & TeamName)
Next

The program throws the exception:

1355265.png

Can some tell me what I did wrong?



MRM256

Continue reading...
 
Back
Top