在数据集中的三个表之间创建关系

在数据集中的三个表之间创建关系

本文介绍了在数据集中的三个表之间创建关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在创建动态菜单控件,并且此菜单将从三个表中获取数据,因此我需要在DataSet中的三个表之间创建关系,以使XmlDataSource使用它为Menu控件提供Data

表是类别(作为父项-菜单中的顶级项目)

Hello

I''m in Creating Dynamic Menu control and this menu will get the Data From three tables , so i need to Create Relation Between The Three Tables in The DataSet to make the XmlDataSource use it to supply the Menu control with Data

the tables is Category (as parent - top level item in the menu)

CREATE TABLE [dbo].[Category] (

            [CategoryID] [int]  PRIMARY KEY IDENTITY ,

            [CategoryName] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

            [Remarks] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

) ON [PRIMARY]

GO

--

CategorySub Table ( as sub Item )

CREATE TABLE [dbo].[CategorySub] (

            [SubCategoryID] [int] NOT NULL ,

            [CategoryIDToSub] [int] NULL ,

            [SubCategoryName] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

            [RcatID] [int] NULL ,

            [RsubID] [int] NULL ,

            [Rsub2ID] [int] NULL ,

            [Remarks] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

) ON [PRIMARY]
-----

CategorySub2 (As second level of sub - sub sub item)



CREATE TABLE [dbo].[CategorySub2] (

            [Sub2CategoryID] [int] NOT NULL ,

            [SubCategoryID] [int] NULL ,

            [Sub2CategoryName] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

            [RcatID] [int] NULL ,

            [RsubID] [int] NULL ,

            [Rsub2ID] [int] NULL ,

            [Remarks] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

) ON [PRIMARY]

GO



希望为我提供正确的关系

谢谢



hope to supply me with the right Relation

Thanks

推荐答案

CREATE TABLE
ID INT PRIMARY KEY IDENTITY,
ParentID INT NULL
NAME [nvarchar] (500) NOT NULL



数据会像这样

1,null,Main
2,1,Child1
3,1,Child2
4,2,SubChild1

对于此层次结构

主要
> Child1
>> SubChild1
> Child2



The data would be like this

1, null, Main
2, 1, Child1
3, 1, Child2
4, 2, SubChild1

for this hierarchy

Main
> Child1
>> SubChild1
> Child2


这篇关于在数据集中的三个表之间创建关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 03:13