嗨我正在尝试在加载会话变量时将表连接在一起下面是我的代码
Dim cmdstring As String = "SELECT * FROM Users.Location_Code = Location.Location_Code =
Medical_Equipment.Location_Code WHERE Staff_No = @StaffNo"
我正在尝试3个表连接,然后这个数据将在网格视图中显示。是否可以在此字符串中进行连接?
答案 0 :(得分:1)
是的,这是可能的。但是您需要具有适当的SQL JOIN
语法。您当前的SQL查询没有意义。它应该看起来像这样(我假设Staff_No是Users表中的一列):
Dim cmdstring As String = _
"SELECT * FROM Users u " & _
"INNER JOIN Location l on l.Location_Code = u.Location_Code " & _
"INNER JOIN Medical_Equipment m on m.Location_Code = u.Location.Location_Code " & _
"WHERE u.Staff_No = @StaffNo"