So basically, i have 2 tables, Tenants and Owners. My stored procedure is inner joining to display the select results in textboxes. But unfortunately, the query is only pulling from the owner table and not both. I get an error when trying to display from the tenant table that the column does not exist.
@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 trying to get a result from the procedure.
private void LoadInfo(string ID)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
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"].ToString();
}
}