Stack Exchange
Compile error when adding SQL query to VB code
Why do I get errors, every time I put my SQL query code into my VB.NET?
Here's my code:
Imports System.Data.OleDb
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles                                                                   MyBase.Load
        Call connection()
        Dim ds As New DataSet
        Dim dt As New DataTable
        Dim da As New OleDbDataAdapter
        ds.Tables.Add(dt)
        da = New OleDbDataAdapter("SELECT T_Order.Order_ID, T_Order.Customer_ID, T_Customer.Fname, T_Customer.Mname, T_Customer.Lname, T_Order.Employee_id, T_Employee.Employee_name
        FROM ( INNER JOIN ((T_Employee INNER JOIN (T_Customer INNER JOIN T_Order ON     T_Customer.Customer_ID = T_Order.Customer_ID) ON T_Employee.Employee_ID = T_Order.Employee_id) INNER JOIN T_OrderDetail ON T_Order.Order_ID = T_OrderDetail.Order_ID) ON T_Product.Product_Code = T_OrderDetail.Product_Code", cn)
        da.Fill(dt)
        DataGridView1.DataSource = dt.DefaultView

Here's the error output:


Check your query....Why is there an inner join after from?

You don't need cover all in brackets like that....You can just type inner join between the tables and have the on conditions at once.... After specifying all the tables

You should make those error 2 line into 1 line like below
da = New OleDbDataAdapter("SELECT T_Order.Order_ID, T_Order.Customer_ID, T_Customer.Fname, T_Customer.Mname, T_Customer.Lname, T_Order.Employee_id, T_Employee.Employee_name FROM ( INNER JOIN ((T_Employee INNER JOIN (T_Customer INNER JOIN T_Order ON     T_Customer.Customer_ID = T_Order.Customer_ID) ON T_Employee.Employee_ID = T_Order.Employee_id) INNER JOIN T_OrderDetail ON T_Order.Order_ID = T_OrderDetail.Order_ID) ON T_Product.Product_Code = T_OrderDetail.Product_Code", cn)

In VB can not assign multiline string like C.
If you need multiline string in VB, You should do like this
str = "string1" & _ 
      "string2" & _
      "string3"

So, your code will be as below.
da = New OleDbDataAdapter("SELECT T_Order.Order_ID, T_Order.Customer_ID, T_Customer.Fname, T_Customer.Mname, T_Customer.Lname, T_Order.Employee_id, T_Employee.Employee_name" & _
"FROM ( INNER JOIN ((T_Employee INNER JOIN (T_Customer INNER JOIN T_Order ON     T_Customer.Customer_ID = T_Order.Customer_ID) ON T_Employee.Employee_ID = T_Order.Employee_id) INNER JOIN T_OrderDetail ON T_Order.Order_ID = T_OrderDetail.Order_ID) ON T_Product.Product_Code = T_OrderDetail.Product_Code", cn)

