5。 In the Add Connection dialog box; fill in the database file name。 For this example; enter
the name lottery。 Visual Basic Express will automatically add an 。mdf extension to the
file name to indicate that it is a SQL Server file and save it in your My Documents folder
by default。 Click OK to add the connection and select Yes when asked to choose to create
the file if it doesn’t exist。
6。 The Choose Your Data Connection screen reappears with your data connection filled
in。 Click Next。
7。 Since we’re using a SQL Server Express Edition driver for this example; the dialog box
shown in Figure 14…2 appears。 It asks if the database file can be copied into the project。
Click Yes。
8。 You are asked if you want the application configuration information added to the project。
Click Next to add the information。
9。 The Choose Your Database Objects screen appears。 Since this is a SQL Server Express
Edition file; it doesn’t have any tables。 If the database connection referenced a relational
database that already existed; database objects would be available。 Click Finish。
…………………………………………………………Page 400……………………………………………………………
378 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…2。 Adding the SQL Server Express Edition file to the local project
Visual Basic Express will rebuild your project。 When it is finished; the result will be similar
to the project structure shown in Figure 14…3。
Figure 14…3。 Modifications made to the Visual Basic Express project
The Visual Basic Express project contains a reference to a file that is provided by Microsoft
SQL Server Express Edition。 The diagram shown earlier in Figure 14…1 indicates that a database
server is another process that you access using a client library。 In about 80% of the cases; this is
true; but some database servers are file…based。 These types of databases are used in simpler
single…user database applications。 From a programming perspective; nothing changes; and the
source code should not even be aware of whether the database is a file or server process。
Adding the Tables
In Visual Basic Express; you can add tables to your database using the Database Explorer。
Through the Database Explorer; you can modify all of the data objects available within the
database。 Here are the general steps for adding a table:
1。 Right…click the lottery。mdf file in the Solution Explorer and select Open to open the
Database Explorer。 The Database Explorer displays information about the database。
2。 Right…click the Tables node and select Add New Table to open a window for creating the
new table; as shown in Figure 14…4。
3。 Specify the column name and type for each column in the table。 You can also specify
other details about each column; such as its length and whether it must be unique。
4。 Once you have entered the column information; save the table (Ctrl+S) and give it a
name。 For this example; we will add three tables: draws; persons; and winners。 The following
sections describe the columns and types for these tables。
…………………………………………………………Page 401……………………………………………………………
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 379
Figure 14…4。 Creating a new table
Each column of a table must have a name and type。 Just as Visual Basic has types; so does
a database。 What is frustrating about database types is that they are similar but not identical to
Visual Basic types。 To make things even more frustrating; not all database implementations
have the exact same types。 Fortunately; if you use the Visual Studio tools; the wizard will map
a specific database type to a Visual Basic type。
■Tip The Microsoft Visual Studio documentation has an excellent reference on the various data types
and their accuracy。 See the “Data Types” section of the Microsoft SQL Server Books Online documentation
(http://msdn2。microsoft。/en…us/library/ms130214。aspx)。
Draws Table
The draws table contains all of the drawn lottery numbers。 Table 14…1 shows the column names
and types for this table。
…………………………………………………………Page 402……………………………………………………………
380 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
Table 14…1。 Draws Table Columns
Name Type
draw_date datetime
first_number int
second_number int
third_number int
fourth_number int
fifth_number int
sixth_number int
bonus int
The draw_date column holds the date of the draw。 The declared type is datetime; which
is like the datetime type in 。 However; you will need to be careful in mapping types; as
explained in Chapter 3。
The rest of the columns represent a number in the winning draw; including the bonus
number。 As in Visual Basic; SQL Server includes various numeric types。 The number columns
in the draws table are declared as the int type。
■Note The one SQL Server numeric type that does not exist in is numeric。 This type behaves like the
decimal type
小说推荐
- 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章