consistency check; so that the drawing date must exist in the database before you can add a
winner for that date。 We will define two relations: winners with draws and winners with persons。
Remember that the winners table is a cross…reference between the persons and draws table。
Follow these steps to define the relations:
1。 Double…click lotteryDataSet。xsd in the Solution Explorer。 You will see a message indi
cating that the Dataset Designer has no data。
2。 Drag and drop each of the three tables you created earlier from the Database Explorer
onto the surface of the Dataset Designer; as shown in Figure 14…6。 This automatically
adds default support for the three tables。
Figure 14…6。 Dataset Designer with the three tables
…………………………………………………………Page 410……………………………………………………………
388 CH AP T E R 1 4 ■ L E A R N I N G A B OU T R E L A TI O N AL DA TA B AS E D AT A
3。 To build a relation; right…click the data generator surface and choose Add Relation。
The Relation dialog box appears。 This dialog box allows you to associate two tables via
a specific field。
4。 As shown in Figure 14…7; specify winners as the parent table and persons as the child。
The key column is id。 Click OK to create the relation。
Figure 14…7。 Creating the winners and persons relation
The winners and draws relation is created in the same way as the winners and persons relation;
except that the columns linked are draw_date; as shown in Figure 14…8。
After you have created both relations; the Dataset Designer surface should look like
Figure 14…9。
Figure 14…9 illustrates a well…defined database structure that includes relations。 The structure
is very important for the Dataset Designer; because it defines how the generated code will appear。
Look closely at Figure 14…9 and notice how each table representation shows Fill; GetData() at
the bottom。 The Fill() and GetData() methods are used to retrieve the data from the database
and convert it into data that Visual Basic can process。
…………………………………………………………Page 411……………………………………………………………
C HA P TE R 1 4 ■ L E AR N I N G AB O U T R E L AT IO N A L D AT AB A SE D A TA 389
Figure 14…8。 Creating the winners and draws relation
Figure 14…9。 Dataset Designer surface with all tables and relations
If you were to click the table adapter; the Dataset Designer would display the properties;
similar to Figure 14…10。
…………………………………………………………Page 412……………………………………………………………
390 CH AP T E R 1 4 ■ L E A R N I N G A B OU T R E L A TI O N AL DA TA B AS E D AT A
Figure 14…10。 Properties of Dataset Designer table structure
The properties show the exact syntax of the SQL INSERT and SELECT mands。 Remember
these two statements are used to add and select data from database tables。 This illustrates that
the Dataset Designer code is no different than the ADO code (except the dataset is a cache)。
Now consider the following code; generated by the Dataset Designer; to bind the columns
of the draws table to the generated data structure (in lotteryDataSet。Designer。vb)。
_
Private Sub InitAdapter()
Me。_adapter = New Global。System。Data。SqlClient。SqlDataAdapter
Dim tableMapping As Global。System。Data。mon。DataTableMapping =
New Global。System。Data。mon。DataTableMapping
tableMapping。SourceTable = 〃Table〃
tableMapping。DataSetTable = 〃draws〃
tableMapping。ColumnMappings。Add(〃draw_date〃; 〃draw_date〃)
tableMapping。ColumnMappings。Add(〃first_number〃; 〃first_number〃)
tableMapping。ColumnMappings。Add(〃second_number〃; 〃second_number〃)
tableMapping。ColumnMappings。Add(〃third_number〃; 〃third_number〃)
tableMapping。ColumnMappings。Add(〃fourth_number〃; 〃fourth_number〃)
tableMapping。ColumnMappings。Add(〃fifth_number〃; 〃fifth_number〃)
tableMapping。ColumnMappings。Add(〃sixth_number〃; 〃sixth_number〃)
tableMapping。ColumnMappings。Add(〃bonus〃; 〃bonus〃)
Me。_adapter。TableMappings。Add(tableMapping)
Me。_adapter。Insertmand = New Global。System。Data。SqlClient。Sqlmand
Me。_adapter。Insertmand。Connection = Me。Connection
Me。_adapter。Insertmand。mandText = 〃INSERT INTO 'dbo'。'draws'
('draw_date'; 'first_number'; 'second_number'; 'third_n〃& _
〃umber'; 'fourth_number'; 'fifth_number'; 'sixth_number'; 'bonus')
…………………………………………………………Page 413……………………………………………………………
C HA P TE R 1 4 ■ L E AR N I N G AB O U T R E L AT IO N A L D AT AB A SE D A TA 391
VALUES (@draw_〃& _
〃date; @first_number; @second_number; @third_number; @fourth_number;
@fifth_numbe〃& _
〃r; @sixth_number; @bonus)〃
Me。_adapter。Insertmand。mandType = Global。System。Data。mandType。Text
Me。_adapter。Insertmand。Parameters。Add(New
Global。System。Data。SqlClient。SqlParameter(〃@draw_date〃;
Global。System。Data。SqlDbType。DateTime; 0;
Global。System。Data。ParameterDirection。Input; 0; 0; 〃draw_date〃;
Global。System。Data。DataRowVersion。Current; false; Nothing; 〃〃; 〃〃; 〃〃))
Me。_adapter。Insertmand。Parameters。Add(New
Global。System。Data。SqlClient。SqlParameter(〃@first_number〃;
Global。System。Data。SqlDbType。Int; 0;
Global。System。Data。ParameterDirection。Input; 0; 0; 〃first_number〃;
Global。System。Data。DataRow
小说推荐
- oracle从入门到精通(PDF格式)
- -Page 1-Oracle 从入门到精通-Page 2-资源来自网络,仅供学习 Oracle 从入门到精通一、SQL 8
- 其他
- 最新章:第37章
- C语言游戏编程从入门到精通(PDF格式)
- -Page 1-Page 2-Page 3-Page 4-Page 5-Page 6-Page 7-Page 8-Page 9-Page 10-Page 11-Page 12-Page 13-Page 14
- 其他
- 最新章:第4章
- Java编程思想第4版[中文版](PDF格式)
- -Page 1-Page 2《Thinking In Java》中文版作者:Bruce Eckel主页:http/BruceEckel.编译:Trans Bot主页:http/memberease~transbot致谢-献给那些直到现在仍在孜孜不倦创造下一代计算机语言的人们!指导您利用万维网的语言进
- 其他
- 最新章:第295章
- 深入浅出MFC第2版(PDF格式)
- -Page 1-Page 2-山高月小山高月小 水落石出水落石出山高月小山高月小 水落石出水落石出-Page 3-深入淺出MFC(第版 使用Visual C 5.0 MFC 4.2)Dissecting MFC(Second Edition Using Visual C 5.0 MFC 4.2)侯俊
- 其他
- 最新章:第309章
- VC语言6.0程序设计从入门到精通
- -Page 1-Visual C 6.0 程序设计从入门到精通求是科技 王正军 编著
- 其他
- 最新章:第136章
- SQL 21日自学通(V3.0)(PDF格式)
- -Page 1-SQL 21 日自学通(V1.0 翻译人 笨猪目录目录 1译者的话 14第一周概貌 16从这里开始 16
- 其他
- 最新章:第170章
- 2008年青年文摘精编版
- 作者:中国青年出版社“初恋”的惩罚.作者:凡 凡 文章来源《真情》2005年第4期 点击数:6608 更新时间:2005-6-5过了年,我就十八岁了。离高考只剩下四个多月了。这一段,班里的男女生相互间递纸条、写情书、约会等地下活动慢慢的多了起来。我这个“尖子生”也突然感到了不安、慌乱,并且自责。不知
- 文学名著
- 最新章:第230章
- SQL语言艺术(PDF格式)
- -Page 1-SQLSSQQLL语言艺术内容介绍本书分为12章,每一章包含许多原则或准则,并通过举例的方式对原则进行解释说明。这些例子大多来自于实际案例,对九种SQL经典查询场景以及其性能影响讨论,非常便于实践,为你数据库应用维护人员阅读。资深 SQL 专家 Stéphane Faroult倾力打
- 其他
- 最新章:第27章
- JMS简明教程(PDF格式)
- -Page 1-JMS1.1规范中文版卫建军2007‐11‐22-Page 2
- 其他
- 最新章:第28章