G
Guest
Hello all. I'm having some (mis?)adventures in databinding a winforms app
and need some guidance.
My data model has 4 tables, let us call them Leases, Terms, LeaseTerms, and
LeaseTermTypes. The idea is that you can setup several definitions of Terms,
several definitions of Leases, and the two of them get related together in
LeaseTerms (standard intermediary tabling to avoid many-to-many). On
LeaseTerms is a foreign key to LeaseTermType (for clarity the create script
for these tables is at the bottom of the post)
On my WinForm app I have 2 comboboxes - one for LeaseTermType and the other
for Terms. What I want to do is for whatever LeaseTermType that has been
selected, I want to populate the 2nd combo box with all associated
Lease.LeaseTermName values (going through the LeaseTerms table). I'm
currently trying to do this using BindSoucres that bind to the relationships
defined in my dataset.
Now, this all currently works fine and dandy except that from the LeaseTerms
perspective, there's a 1-to-1 relationship from LeaseTerms to Leases. So
what's happening is that my 2nd combobox is only displaying 1 record rather
than a record for each of the records contained in the filtered LeaseTerms
table.
Is there any way to get all the Leases rather than just the 1 using the
built-in UI binding? I could write code to do all this, but ideally I'd like
to spend 15 seconds pointing and clicking rather than a few minutes hacking
code.
Any help and or guidance is appreciated.
Here's the script for our example DB.
/****** Object: Table [dbo].[Leases] Script Date: 10/23/2006 10:59:14
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Leases](
[LeaseID] [uniqueidentifier] NOT NULL,
[LeaseName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
PRIMARY KEY CLUSTERED
(
[LeaseID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[LeaseTerms] Script Date: 10/23/2006
10:59:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[LeaseTerms](
[LeaseTermID] [uniqueidentifier] NOT NULL,
[LeaseID] [uniqueidentifier] NULL,
[TermID] [uniqueidentifier] NULL,
[LeaseTermTypeID] [uniqueidentifier] NULL,
PRIMARY KEY CLUSTERED
(
[LeaseTermID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[LeaseTermTypes] Script Date: 10/23/2006
10:59:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[LeaseTermTypes](
[LeaseTermTypeID] [uniqueidentifier] NOT NULL,
[LeaseTermTypeName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
PRIMARY KEY CLUSTERED
(
[LeaseTermTypeID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[Terms] Script Date: 10/23/2006 10:59:15
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Terms](
[TermID] [uniqueidentifier] NOT NULL,
[TermName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
PRIMARY KEY CLUSTERED
(
[TermID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
USE [DeleteMe]
GO
ALTER TABLE [dbo].[LeaseTerms] WITH CHECK ADD CONSTRAINT
[FK_LeaseTerms_Leases] FOREIGN KEY([LeaseID])
REFERENCES [dbo].[Leases] ([LeaseID])
GO
ALTER TABLE [dbo].[LeaseTerms] WITH CHECK ADD CONSTRAINT
[FK_LeaseTerms_LeaseTermTypes] FOREIGN KEY([LeaseTermTypeID])
REFERENCES [dbo].[LeaseTermTypes] ([LeaseTermTypeID])
GO
ALTER TABLE [dbo].[LeaseTerms] WITH CHECK ADD CONSTRAINT
[FK_LeaseTerms_Terms] FOREIGN KEY([TermID])
REFERENCES [dbo].[Terms] ([TermID])
and need some guidance.
My data model has 4 tables, let us call them Leases, Terms, LeaseTerms, and
LeaseTermTypes. The idea is that you can setup several definitions of Terms,
several definitions of Leases, and the two of them get related together in
LeaseTerms (standard intermediary tabling to avoid many-to-many). On
LeaseTerms is a foreign key to LeaseTermType (for clarity the create script
for these tables is at the bottom of the post)
On my WinForm app I have 2 comboboxes - one for LeaseTermType and the other
for Terms. What I want to do is for whatever LeaseTermType that has been
selected, I want to populate the 2nd combo box with all associated
Lease.LeaseTermName values (going through the LeaseTerms table). I'm
currently trying to do this using BindSoucres that bind to the relationships
defined in my dataset.
Now, this all currently works fine and dandy except that from the LeaseTerms
perspective, there's a 1-to-1 relationship from LeaseTerms to Leases. So
what's happening is that my 2nd combobox is only displaying 1 record rather
than a record for each of the records contained in the filtered LeaseTerms
table.
Is there any way to get all the Leases rather than just the 1 using the
built-in UI binding? I could write code to do all this, but ideally I'd like
to spend 15 seconds pointing and clicking rather than a few minutes hacking
code.
Any help and or guidance is appreciated.
Here's the script for our example DB.
/****** Object: Table [dbo].[Leases] Script Date: 10/23/2006 10:59:14
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Leases](
[LeaseID] [uniqueidentifier] NOT NULL,
[LeaseName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
PRIMARY KEY CLUSTERED
(
[LeaseID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[LeaseTerms] Script Date: 10/23/2006
10:59:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[LeaseTerms](
[LeaseTermID] [uniqueidentifier] NOT NULL,
[LeaseID] [uniqueidentifier] NULL,
[TermID] [uniqueidentifier] NULL,
[LeaseTermTypeID] [uniqueidentifier] NULL,
PRIMARY KEY CLUSTERED
(
[LeaseTermID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[LeaseTermTypes] Script Date: 10/23/2006
10:59:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[LeaseTermTypes](
[LeaseTermTypeID] [uniqueidentifier] NOT NULL,
[LeaseTermTypeName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
PRIMARY KEY CLUSTERED
(
[LeaseTermTypeID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[Terms] Script Date: 10/23/2006 10:59:15
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Terms](
[TermID] [uniqueidentifier] NOT NULL,
[TermName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
PRIMARY KEY CLUSTERED
(
[TermID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
USE [DeleteMe]
GO
ALTER TABLE [dbo].[LeaseTerms] WITH CHECK ADD CONSTRAINT
[FK_LeaseTerms_Leases] FOREIGN KEY([LeaseID])
REFERENCES [dbo].[Leases] ([LeaseID])
GO
ALTER TABLE [dbo].[LeaseTerms] WITH CHECK ADD CONSTRAINT
[FK_LeaseTerms_LeaseTermTypes] FOREIGN KEY([LeaseTermTypeID])
REFERENCES [dbo].[LeaseTermTypes] ([LeaseTermTypeID])
GO
ALTER TABLE [dbo].[LeaseTerms] WITH CHECK ADD CONSTRAINT
[FK_LeaseTerms_Terms] FOREIGN KEY([TermID])
REFERENCES [dbo].[Terms] ([TermID])