A
Andrea Caldarone
Hi all,
In my project (VB.Net 2003) I've plenty tables linked each other via
DataRelation, for example let's analyze this couple:
Parent Table [Clienti]
Child Table [Indirizzi]
theese two tables exist in a SQL Server 2005 Database, and theese are their
definitions:
CREATE TABLE [dbo].[Clienti](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Cognome] [nvarchar](30) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Clienti_Cognome] DEFAULT (''),
[Nome] [nvarchar](30) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Clienti_Nome] DEFAULT (''),
[nvarchar](50) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Clienti_Email] DEFAULT (''),
[Note] [ntext] COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Clienti_Note] DEFAULT (''),
CONSTRAINT [PK_Clienti] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
CREATE TABLE [dbo].[Indirizzi](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ClientiID] [int] NOT NULL CONSTRAINT [DF_Indirizzi__ClientiID] DEFAULT
(0),
[Indirizzo] [nvarchar](50) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Indirizzi_Indirizzo] DEFAULT (''),
[CAP] [nvarchar](6) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Indirizzi_CAP] DEFAULT (''),
[Città] [nvarchar](50) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Indirizzi_Città] DEFAULT (''),
CONSTRAINT [PK_Indirizzi_] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
USE [NENA]
GO
ALTER TABLE [dbo].[Indirizzi] WITH NOCHECK ADD CONSTRAINT
[FK_Indirizzi_Clienti] FOREIGN KEY([ClientiID])
REFERENCES [dbo].[Clienti] ([ID])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Indirizzi] CHECK CONSTRAINT [FK_Indirizzi_Clienti]
GO
In my project theese two SQL Tables became two DataTable of one main dataset
with two distinct adapters (aClienti and aIndirizzi) that fills with
..FillSchema and then with .Fill the main dataset. After that I declare the
dataset's relation as:
dsMain.Relations.Add(New DataRelation("Clienti_Indirizzi",
..Tables("Clienti").Columns("ID"),
..Tables("Indirizzi").Columns("ClientiID")))
Then I bind the parent table to a DataGrid and the DefaultView of the child
table to an other datagrid.
When I select one row of the "parent" datagrid, I simply apply a different
..RowFilter to the dsMain.Tables("Indirizzi") table and all works fine.
Here is my problem:
when I create a new record into the "child" DataGrid, I expect that the
[ClientiID] field of the "child" row is AUTOMATICALLY filled the "parent"
value, but it is filled with is default value (i.e. 0)
have I to manually specify .DefaultValue for the "child" table every time I
select a row on the "parent" table?
Thanks all
In my project (VB.Net 2003) I've plenty tables linked each other via
DataRelation, for example let's analyze this couple:
Parent Table [Clienti]
Child Table [Indirizzi]
theese two tables exist in a SQL Server 2005 Database, and theese are their
definitions:
CREATE TABLE [dbo].[Clienti](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Cognome] [nvarchar](30) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Clienti_Cognome] DEFAULT (''),
[Nome] [nvarchar](30) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Clienti_Nome] DEFAULT (''),
[nvarchar](50) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Clienti_Email] DEFAULT (''),
[Note] [ntext] COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Clienti_Note] DEFAULT (''),
CONSTRAINT [PK_Clienti] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
CREATE TABLE [dbo].[Indirizzi](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ClientiID] [int] NOT NULL CONSTRAINT [DF_Indirizzi__ClientiID] DEFAULT
(0),
[Indirizzo] [nvarchar](50) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Indirizzi_Indirizzo] DEFAULT (''),
[CAP] [nvarchar](6) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Indirizzi_CAP] DEFAULT (''),
[Città] [nvarchar](50) COLLATE Latin1_General_CI_AS NOT NULL CONSTRAINT
[DF_Indirizzi_Città] DEFAULT (''),
CONSTRAINT [PK_Indirizzi_] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
USE [NENA]
GO
ALTER TABLE [dbo].[Indirizzi] WITH NOCHECK ADD CONSTRAINT
[FK_Indirizzi_Clienti] FOREIGN KEY([ClientiID])
REFERENCES [dbo].[Clienti] ([ID])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Indirizzi] CHECK CONSTRAINT [FK_Indirizzi_Clienti]
GO
In my project theese two SQL Tables became two DataTable of one main dataset
with two distinct adapters (aClienti and aIndirizzi) that fills with
..FillSchema and then with .Fill the main dataset. After that I declare the
dataset's relation as:
dsMain.Relations.Add(New DataRelation("Clienti_Indirizzi",
..Tables("Clienti").Columns("ID"),
..Tables("Indirizzi").Columns("ClientiID")))
Then I bind the parent table to a DataGrid and the DefaultView of the child
table to an other datagrid.
When I select one row of the "parent" datagrid, I simply apply a different
..RowFilter to the dsMain.Tables("Indirizzi") table and all works fine.
Here is my problem:
when I create a new record into the "child" DataGrid, I expect that the
[ClientiID] field of the "child" row is AUTOMATICALLY filled the "parent"
value, but it is filled with is default value (i.e. 0)
have I to manually specify .DefaultValue for the "child" table every time I
select a row on the "parent" table?
Thanks all