0

I wrote following code:

 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();

I am getting following error

Additional information: Incorrect syntax near '.'.

I am newbie for Joins Please help me out...

2
  • What is the value of txtId.Text Commented Nov 17, 2014 at 6:06
  • Please correct your query. After Inner join, you should use equal to operator between only two columns or you should use And/OR operator in between. You have multiple column comparision after ON. Commented Nov 17, 2014 at 6:08

2 Answers 2

2

You missed And operator in 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
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Pradeep, But I am getting another error Additional information: Incorrect syntax near the keyword 'INNER'.
I used same code what you posted and tried to execute but it is showing error " Incorrect syntax near the keyword 'INNER'".
@surya You were missing some tables in join. updated check now.
Thank you so much worked for me now learned new thing from you
0

You need to add AND between multiple join conditions. Also, add a space after EMP_name on.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.