Requête SQL tirant uniquement des données d'une table

Donc, fondamentalement, j'ai 2 tables, locataires et propriétaires. Ma procédure stockée est une jointure interne pour afficher les résultats de sélection dans des zones de text. Mais malheureusement, la requête tire seulement de la table du propriétaire et pas les deux. J'obtiens une erreur en essayant d'afficher de la table de locataire que la colonne n'existe pas.

@ID varchar(4) SELECT owner_table.ownerID AS ownID, tenant_table.tenantID, owner_table.apt_num AS aptNum, owner_table.first_name AS own_first, owner_table.last_name AS own_last, owner_table.address AS own_address, owner_table.city AS own_city, owner_table.state AS own_state, owner_table.zip AS own_zip, owner_table.phone AS own_phone, owner_table.phone_2 AS own_phone2, owner_table.notes AS own_notes, owner_table.last_update AS own_lastUpdate, tenant_table.ownerID AS ten_ownID, tenant_table.last_name, tenant_table.keyID, tenant_table.storage, tenant_table.phone, tenant_table.phone_2, tenant_table.notes, tenant_table.complaints, tenant_table.lease_end, tenant_table.last_update, tenant_table.apt_status FROM owner_table INNER JOIN tenant_table ON owner_table.ownerID = @ID AND tenant_table.tenantID = @ID RETURN 

Code essayant d'get un résultat de la procédure.

 private void LoadInfo(ssortingng ID) { using (SqlConnection connection = new SqlConnection(connectionSsortingng)) { SqlCommand Command = new SqlCommand(); Command.Connection = connection; Command.CommandText = "MoreInfoData"; Command.CommandType = CommandType.StoredProcedure; Command.Parameters.Add(new SqlParameter("@ID", SqlDbType.VarChar, 4)).Value = ID; table = new DataTable(); SqlDataAdapter MyAdapter = new SqlDataAdapter(); MyAdapter.SelectCommand = Command; MyAdapter.Fill(table); if (table.Rows.Count > 0) { ten_name.Text = table.Rows[0]["last_name"].ToSsortingng(); } } 

Modifier pour utiliser l'alias de colonne:

 ten_name.Text = table.Rows[0]["own_last"].ToSsortingng(); 

Vous avez changé votre nom de champ en tant que own_last, donc bien sûr, il n'existe pas. owner_table.last_name AS own_last . Donc, vous devriez changer votre code en

ten_name.Text = table.Rows[0]["own_last"].ToSsortingng();

Avez-vous essayé d'append un alias pour tenable_table.last_name ?:

 SELECT .... tenant_table.last_name AS tenant_last_name 

et alors:

 ten_name.Text = table.Rows[0]["tenant_last_name"].ToSsortingng(); 

Pouvez-vous exécuter ceci et voir ce qui vient dans la sortie, devrait énumérer tous vos noms de colonne pour la datatable que vous récupérez.

 if (table.Rows.Count > 0) { foreach (System.Data.DataColumn col in table.Columns) { System.Diagnostics.Debug.WriteLine(col.ColumnName); } } 

Dans l'set, en quelque sorte tout ce que j'ai enregistré à ma requête à l'époque ne serait pas save pour une raison quelconque. Cela a fini par être le problème après tout. Merci pour votre aide.