1. Trang chủ
  2. » Công Nghệ Thông Tin

Beginning VB 2008 Databases From Novice to Professional phần 2 pdf

44 288 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 44
Dung lượng 1,99 MB

Nội dung

Getting to Know Your Tools Now that you’ve installed the tools you’ll use in this book, we’ll show you just enough about them so you can use them easily to do the things you need to do the rest of the way. We’ll focus on Visual Studio 2008 and SQL Server Management Studio Express (SSMSE). In this chapter, we’ll cover the following: • Understanding how versions of Microsoft .NET Framework work in the green bit and red bit assembly model • Using Microsoft Visual Studio 2008 • Using SQL Server Management Studio Express Microsoft .NET Framework Versions and the Green Bit and Red Bit Assembly Model As mentioned in Chapter 1, Visual Studio 2008 supports various .NET Framework versions. To ensure this compatibility, Visual Studio 2008 comes installed with .NET 2.0 and .NET 3.0 along with .NET 3.5. Navigate to C:\WINDOWS\Microsoft.NET\Framework, and you will see individual folders for each .NET Framework version installed, as shown in Figure 2-1. Figure 2-1. .NET F r ame wor k versions installed in Visual Studio 2008 15 CHAPTER 2 9470ch02final.qxd 2/21/08 3:04 PM Page 15 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Having the various .NET Framework versions on a given Visual Studio 2008 system could a lso be achieved by installing one .NET Framework version on top of another version—for example, .NET 3.0 installed atop .NET 2.0, and then .NET 3.5 installed atop .NET 3.0. .NET Framework 3.5 holds green bit assemblies, which are additional assemblies that can be installed above other existing .NET Framework assemblies without affecting them. For example, installing .NET 3.0 on a .NET 2.0 system does not affect the .NET 2.0 assemblies. In a similar manner, .NET 3.5 assemblies do not affect either .NET 2.0 or 3.0 if you install .NET 3.5 on top of them. See the list of green bit assemblies in Figure 2-2. Figure 2-2. .NET 3.5 green bit assemblies Red bit assemblies are the assemblies that ship as either part of the platform or part of a development tool. For example, Windows Vista ships WPF, WCF, and so forth, and Visual Studio 2008 ships .NET 2.0. In addition, assemblies delivered as service packs, hot fixes, or updates are also considered to be red bit assemblies. Using Microsoft Visual Studio 2008 Now it’s time for you to familiarize yourself with the workings of Visual Studio 2008. Follow these steps: 1. Select Start ➤ Programs ➤ Microsoft Visual Studio 2008 and then click Microsoft Visual S tudio 2008. Y ou will see a splash scr een for Visual Studio 2008, followed by the start page (see Figure 2-3). ■Note The first time you load Visual Studio 2008, it may take a little longer to get to the start pa ge than it will eventually, as some initial configurations need to be performed. CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS16 9470ch02final.qxd 2/21/08 3:04 PM Page 16 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Figure 2-3. Start page of Microsoft Visual Studio 2008 2. To take a look at the project templates, click File ➤ New ➤ Project. This opens the New Project window, shown in Figure 2-4, where you will see all the project templates you can use with Visual Basic. Figure 2-4. P roject templates in the New Project window CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS 17 9470ch02final.qxd 2/21/08 3:04 PM Page 17 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 3. While selecting your desired project template, you can also choose the .NET Frame- w ork version you want your application to be compatible with. To develop .NET 2.0– or 3.0–specific applications in Visual Studio 2008, you have to explicitly define the .NET Framework version before you choose the project template. To specify a .NET version, click the drop-down list button just below the title bar and on the right side of the New Project window, as you see in Figure 2-5. Figure 2-5. Choosing the .NET Framework version Try It Out: Creating a Simple Console Application Project Using Visual Studio 2008 In this example, you’ll create a simple Console Application project in Visual Studio 2008: 1. Open Visual Studio 2008 if it’s not already open. 2. Click F ile ➤ N ew ➤ P r oject, and select V isual Basic language’s Console Application template. In the Name text box of the selected project template, type FirstApp (see Figure 2-6) and click OK. CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS18 9470ch02final.qxd 2/21/08 3:04 PM Page 18 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Figure 2-6. Creating a new Console Application project 3. Now replace the code of Module1.vb with the code in Listing 2-1. Listing 2-1. Replacement Code for Module1.vb Imports System Imports System.Linq Imports System.Collections.Generic Imports System.Text Namespace FirstApp Class Program Shared Sub Main(ByVal args() As String) Console.WriteLine("Welcome to VB 9.0") Console.ReadLine() End Sub End Class End Namespace CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS 19 9470ch02final.qxd 2/21/08 3:04 PM Page 19 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 4. Run the application by pressing Ctrl+F5. Your results should appear as shown in F igure 2-7. Figure 2-7. Output of your simple Console Application project How It Works Let’s take a look at how the code works, starting with the using directives: Imports System Imports System.Linq Imports System.Collections.Generic Imports System.Text The references to System.Linq, System.Collections.Generic, and System.Text are actu- ally not needed in this small program, since you don’t explicitly use any of their members, but it’s a good habit to always include them, as they are by default part of Program.cs. The following specifies the string to be printed on the console: Console.WriteLine("Welcome to VB 9.0"); The following method specifies that output will be shown to you until you press the Enter key: Console.ReadLine(); Go ahead and close the Visual Studio environment. Next, we’ll get you acquainted with SQL Server Management Studio Express. Using SQL Server Management Studio Express SQL Server Management Studio Express is the GUI interface for SQL Server 2005. It combines the features of two earlier SQL Server GUI tools, Enterprise Manager (also known as Microsoft Management Console) and Query Analyzer, to make database administration and T-SQL development possible from a single interface. We use it in the examples in this book primarily to submit T-SQL, but here we’ll discuss briefly its Object Explorer feature, which lets you view database objects. CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS20 9470ch02final.qxd 2/21/08 3:04 PM Page 20 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Let’s take a quick tour of SSMSE: 1. To open SSMSE, click Start ➤ Programs ➤ Microsoft SQL Server 2005 ➤ SQL Server Management Studio to bring up the window shown in Figure 2-8. Click Connect. Figure 2-8. Connecting to SQL Server 2. A window containing Object Explorer and the Summary tab will appear, and you should be connected to your SQL Server instance named ORCASBETA2_VSTS\ SQLEXPRESS (see Figure 2-9). The top node in Object Explorer should be your SQL Server instance, and the Summary tabbed pane should display folder icons for the five other nodes in Object Explorer. Expand the Databases node in Object Explorer. Figure 2-9. SSMSE Object Explorer and Summary tabbed pane CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS 21 9470ch02final.qxd 2/21/08 3:04 PM Page 21 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 3. Expand the System Databases node, and your screen should resemble that shown in F igure 2-10. As you can see, SSMS has four system databases: • The master database is the main controlling database, and it records all the global information that is required for the SQL Server instance. • The model database works as a template for new databases to be created; in other words, settings of the model database will be applied to all user-created databases. • The msdb database is used by SQL Server Agent for scheduling jobs and alerts. • The tempdb database holds temporary tables and other temporary database objects, either generated automatically by SQL Server or created explicitly by you. The temporary database is re-created each time the SQL Server instance is started, so objects in it do not persist after SQL Server is shut down. Figure 2-10. System databases CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS22 9470ch02final.qxd 2/21/08 3:04 PM Page 22 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 4. Click the AdventureWorks node in Object Explorer, and then click New Query to bring u p a new SQL edit window, as shown in Figure 2-11. As mentioned in Chapter 1, AdventureWorks is a new sample database introduced for the first time with SQL Server 2005. 5. To see a listing of the tables residing inside AdventureWorks, type the query select name from sysobjects where xtype=‘U’ and click the Execute button. The table names will appear in the Results tab (see Figure 2-11). If you navigate to the Messages tab, you will see the message “70 row(s) affected,” which means that the AdventureWorks data- base consists of 70 tables. Figure 2-11. Tables in the AdventureWorks database 6. Click File ➤ Disconnect Object Explorer. CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS 23 9470ch02final.qxd 2/21/08 3:04 PM Page 23 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 7. Click the Northwind node in Object Explorer, and then click New Query. To see the t able names residing inside Northwind, type the query s elect name from sysobjects where xtype=‘U’ and click the Execute button. A listing of tables in the database will appear in the Results tab (see Figure 2-12). If you navigate to the Messages tab, you will see the message “13 row(s) affected,” which means that the Northwind database con- sists of 13 tables. Figure 2-12. Tables in the Northwind database 8. Click File ➤ Disconnect Object Explorer, and then close SQL Server Management Studio Express. Summary In this chapter, we covered just enough about Visual Studio 2008 and SQL Server Management Studio to get you familiar with the kinds of things you’ll do with these tools later in this book. Besides these tools, we also covered a bit about multiple .NET Framework versions on a single system. Now that your tools are installed and configured, you can start learning how to do data- base programming by learning the basics of T-SQL. CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS24 9470ch02final.qxd 2/21/08 3:04 PM Page 24 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com [...]... of server databases include Microsoft SQL Server, Oracle, Sybase, and DB2 27 9470ch03final.qxd 2/ 21/08 3:07 PM Page 28 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 28 CHAPTER 3 s GETTING TO KNOW RELATIONAL DATABASES Here are some other characteristics that differentiate server databases from their desktop counterparts: • Flexibility: Server databases are designed to be very... 9470ch04final.qxd 2/ 21/08 3:03 PM Page 43 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com CHAPTER 4 s WRITING DATABASE QUERIES Figure 4-5 Using the PIVOT operator to summarize data How It Works You begin with the SELECT list and specify the columns and their aliases as you want them to appear in the result set: select CardType , [20 08] as Year2008, [20 09] as Year2009 from Then you... You need to total the cards of a specific type that will be expiring in a particular year Open a New Query window in SSMSE Enter the following query and click Execute You should see the results shown in Figure 4-5 Use AdventureWorks Go select CardType , [20 08] as Year2008, [20 09] as Year2009 from ( select CardType,ExpYear from Sales.CreditCard )piv Pivot ( count(ExpYear) for ExpYear in ( [20 08] , [20 09])... into a consistent state after a transaction fails • Storage management: RDBMSs provide a mechanism for data storage management The internal schema defines how data should be stored Comparing Desktop and Server RDBMS Systems In the industry today, we mainly work with two types of databases: desktop databases and server databases Here, we’ll give you a brief look at each of them Desktop Databases Desktop... query is a technique to extract information from a database You need a query window into which to type your query and run it so data can be retrieved from the database s Note Many of the examples from this point forward require you to work in SSMSE Refer to “Using SQL Server Management Studio Express” in Chapter 2 for instructions if you need to refresh your memory on how to connect to SSMSE Try It Out:...9470ch03final.qxd 2/ 21/08 3:07 PM Page 25 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com CHAPTER 3 Getting to Know Relational Databases N ow that you have gotten to know the tools you’ll use in this book, we’ll step back a bit to give you a brief introduction to the important concepts of the PC database world before diving into the examples In this chapter,... with the CustomerID field of the Orders table; CustomerID is considered a foreign key in the Orders table The link shown between the Customers and Orders tables indicates a one -to- many relationship, as many orders can belong to one customer Here, Customers is referred to as the parent table, and Orders is the child table in the relationship 29 9470ch03final.qxd 2/ 21/08 3:07 PM Page 30 Simpo PDF Merge... this numbering restarts as TerritoryID changes If you look at the result shown in Figure 4-7, you will see that the RowCount column displays numbering from 1 to 12 for all those territories that have TerritoryID value 1 The numbering restarts for the TerritoryID 2 45 9470ch04final.qxd 2/ 21/08 3:03 PM Page 46 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 46 CHAPTER 4 s WRITING... as they do not require complex SQL queries to perform database operations (although some desktop databases also support SQL syntax if you would like to code) Desktop databases generally offer an easy -to- use graphical user interface Server Databases Server databases are specifically designed to serve multiple users at a time and offer features that allow you to manage large amounts of data very efficiently... SELECT statement for the table with column names from which you will be retrieving data, and you also assign a PIVOT operator to the SELECT statement: select CardType,ExpYear from Sales.CreditCard ) piv Pivot Now you need to count the cards of particular type for the years 20 08 and 20 09 as specified in this statement: ( count(ExpYear) for ExpYear in ( [20 08] , [20 09]) )as carddetail The ORDER BY clause will . down. Figure 2- 10. System databases CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS 22 9470ch02final.qxd 2/ 21/08 3:04 PM Page 22 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 4 objects. CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS20 9470ch02final.qxd 2/ 21/08 3:04 PM Page 20 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Let’s take a quick tour of SSMSE: 1. To. the Databases node in Object Explorer. Figure 2- 9. SSMSE Object Explorer and Summary tabbed pane CHAPTER 2 ■ GETTING TO KNOW YOUR TOOLS 21 9470ch02final.qxd 2/ 21/08 3:04 PM Page 21 Simpo PDF

Ngày đăng: 12/08/2014, 10:21

TỪ KHÓA LIÊN QUAN