Skip to main content
2 of 4
edited tags
Mathieu Guindon
  • 75.1k
  • 18
  • 191
  • 463

Return Office Details From Multiple Tables

        public void GetOffice(int syncID)
    {
        string strQry = @"
Select so.SyncID, 
   so.title
From Offices o
Left Outer Join SyncOffices so On so.id = o.SyncID
Where o.SyncID = @syncID
"; 
        
        using (SqlConnection conn = new SqlConnection(Settings.ConnectionString))
        {
            using (SqlCommand objCommand = new SqlCommand(strQry, conn))
            {
                objCommand.CommandType = CommandType.Text;
                objCommand.Parameters.AddWithValue("@syncID", syncID);
                conn.Open();
                SqlDataReader rdr = objCommand.ExecuteReader();

                if (rdr.Read())
                {
                    this.OfficeName= rdr.GetString(1);
                }

                rdr.Close();
            }
        }
    }
ADH
  • 336
  • 4
  • 15