所以基本上,我有 2 张桌子,租户和业主。我的存储过程是内部连接以在文本框中显示选择结果。但不幸的是,查询只是从所有者表中提取,而不是两者。尝试从租户表中显示该列不存在时出现错误。
@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
试图从过程中获得结果的代码。
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();
}
}