SQL 联接多表查询

本文关键字:查询 SQL | 更新日期: 2023-09-27 18:30:34

我写了以下代码:

 cmd = new SqlCommand("Select City.City, Company.Company,Emp_Depart.Department,Emp_Name.Uname from Emp_Name INNER join Emp_Name on" +
            "Emp_Name.Id=Emp_Depart.Id Emp_Name.Id=Company.Id Emp_Name.Id=City.Id where Emp_Name.Id=" + txtId.Text);
 cmd.Connection = con;
 da = new SqlDataAdapter(cmd);
 dt = new DataTable();
 da.Fill(dt);
 txtName .Text = dt.Rows[0][1].ToString().Trim();

我收到以下错误

附加信息:Incorrect syntax near '.'.

我是加入的新手请帮帮我...

SQL 联接多表查询

你错过了And operator join condition

SELECT CITY.CITY,
       COMPANY.COMPANY,
       EMP_DEPART.DEPARTMENT,
       EMP_NAME.UNAME
FROM   EMP_NAME
       INNER JOIN EMP_DEPART
               ON EMP_NAME.ID = EMP_DEPART.ID
       INNER JOIN COMPANY
         ON EMP_NAME.ID = COMPANY.ID
       INNER JOIN CITY
         ON EMP_NAME.ID = CITY.ID 
WHERE EMP_NAME.ID =+ TXTID.TEXT
您需要

在多个连接条件之间添加AND。另外,在 EMP_name on 后添加一个空格。