The « Project » Window (Upper Half)

The « Project » Window (Upper Half)

Down the right-hand side of the screen are two windows that together make up what we refer to here as the « project window ». The upper half provides three options: ❑ Workspace – which shows the drives and files on your local machine and, by default, any mapped folders. You can also add shortcuts to other local or network folders, or to other servers via FTP using the commands on the Workspace menu. Double-clicking a file here opens it in a new editing window. By right-clicking in the Workspace window you can add a shortcut, create a new folder, or create a new file based on one of the standard types available in the New File dialog. We’ll look at the available file types in Types of Files and Wizards later on. ❑ Data – which allows you to connect to a SQL Server or MSDE database and then view, create, and edit tables and stored procedures within that database. The following screenshot shows a connection to a database named WroxCars, and you can see the tables within this database displayed. ❑ Open Items – which lists the edit windows that are currently open within the IDE. You can simply click on one to bring it to the front for editing. Using the Data Window To connect to a data source click the icon at the top of the Data window, as shown in the following screenshot, and enter the connection details for the database. You can generally use Windows authentication for the local SQL Server or MSDE database, or if you prefer you can specify the user name and password for SQL Server authentication. Then, select the database from the drop-down list: There is also an option to create a new database on the specified server. All you do is enter the name for the new database in the dialog that appears, and the database is created and displayed in the Data window.

Working with a Data Source

Once you have at least one database open in the Data window (you can connect to more than one at a time if you wish), the remaining icons at the top of this window are enabled. You can use these icons to work with the database – you can create a new table or stored procedure (using the second icon), or edit existing ones (using the third icon). For example, in the following screenshot, we selected our tblCars table and clicked the Edit icon. You can see the contents of the table, and the row values can be edited directly. Note, however, that this only works if the table has a primary key defined: As well as editing the contents of the table, you can also view the table structure by clicking the link at the bottom of the dialog shown in the previous screenshot: However, you can only edit the table structure if the table is empty. The following screenshot shows a new table that was created by clicking the second (New Item) icon in the Data window. Three columns have been added to it, setting the properties using the controls in the Column Properties section of the dialog:

Querying a Data Source

The fourth icon in the Data window is used to query a data source. If you select an existing table in the Data window first, Web Matrix creates a simple SQL statement that will query and display the entire contents of that table. You can, of course, edit the SQL statement to perform more specific queries if required: The other three icons at the top of the Data window can be used to refresh the contents of the window, delete a table or stored procedure from a database (or even delete an entire database), and disconnect a database from the Data window. This means that the Data window provides a complete environment for working with databases, which is especially useful if you are connecting to MSDE (which, unlike the full version of SQL Server, provides no user interface). Just take care not to select the Delete icon when you only want to disconnect!

Data Tables, Data Controls, and Grid Controls

Data access is at the heart of many web sites and web applications, and Web Matrix makes it easy to perform common tasks that interact with a database. For example, you can drag a table from the list in the Data window and drop it onto a page – 

Formation et coursTélécharger le document complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *