title: C#: Inner Join 4 tables SQL Server
body: <p>I am joining 4 tables in one SQL statement that reads data into objects and fill a gridview as well.  </p>
  
  <p><strong>My question</strong>: Is this a good practice ? does it have any side effects like performance when reading from the database? if so please provide me with some tips in improving it.   </p>
  
  <pre><code>protected void OrdersGridView_SelectedIndexChanged(object sender, EventArgs e)
  {
      string OID = OrdersGridView.SelectedRow.Cells[0].Text;
      OrderIDlbl.Text = "Order# " + OID;
  
      using (SqlConnection con = new SqlConnection(cData.CS))
      {
          con.Open();
          {
              string sql = "select o.*, c.*, oi.*, p.* from Orders as o INNER JOIN Customers as c ON o.CustID = c.CustomerID INNER JOIN OrderItems as oi ON o.OrderID = oi.InvoiceID INNER JOIN Products as p ON p.PartNumber = oi.PartNumb where OrderID ='" + OID + "'";
  
              SqlCommand myCommand = new SqlCommand(sql, con);
              myCommand.CommandTimeout = 15;
              myCommand.CommandType = CommandType.Text;
  
              using (SqlDataReader myReader = myCommand.ExecuteReader())
              {
                  while (myReader.Read())
                  {
                      passid.Text = (myReader["CustID"].ToString());
                      TermsDropdown.Value = (myReader["PaymentTerms"].ToString());
                      PaymentDate.Value = ((DateTime)myReader["PaymentDate"]).ToString("MMMM dd, yyyy");
                      OrderDate.Value = ((DateTime)myReader["OrderDate"]).ToString("MMMM dd, yyyy");
                      SalesRep.Value = (myReader["SalesRep"].ToString());
                      comenttxtbox.Value = (myReader["Comments"].ToString());
                      Discountlbl.Text = "Discount: " + (myReader["Discount"].ToString() + " AED");
                      Totallbl.Text = "Total: " + (myReader["Total"].ToString() + " AED");
                      Statuslbl.Text = (myReader["OrderStatus"].ToString());
                      SelectCustomertxtbox.Value = (myReader["Company"].ToString());
                      Name.Text = "Name: " + (myReader["FName"].ToString()) + " " + (myReader["LName"].ToString());
                      Phone.Text = "Phone: " + (myReader["Phone"].ToString());
                      Mail.Text = "Mail: " + (myReader["Personal_Email"].ToString());
                  }
              }
  
              DataTable dt = new DataTable();
  
              using (SqlDataAdapter da = new SqlDataAdapter(myCommand))
              {
                  da.Fill(dt);
  
                  OrderItemsGridview.DataSource = dt;
                  OrderItemsGridview.EmptyDataText = "No Items";
                  OrderItemsGridview.DataBind();
              }
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/cagmh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cagmh.png" alt="Orders POPUP"></a></p>