Monday, 13 December 2010

This weeks tutorial dealt with working with the Dynamic Data aspect of Visual Studio, giving a brief intoduction towards how it works and its abilities. Within this weeks tutorial we were asked to create a database which already existed, and link it using Dynamic Data. The process of completing this task was as follows:
  • Create a new website, using the standard process, ensuring that C# is selected from the left hand side of the window.
  • Global.ascx will be referred to later, but it provides the other pages in the website, hence its "global" name.
  • Continuing with the process of completing the Dynamic Data task, navigate to the AppData folder and choose to "Add an Exisiting Item" (this can only be done once the Northwind database has been downloaded from the online source). Nothing should happen once the database has been added into the web site.
  • Go back to the directory and add a new item, ensuring that Visual C# is once again selected (this is important otherwise the Global.ascx page won't be able to render the information correctly), then choose "Linq to SQL Classes" - A standard message should then appear on the screen, of which "Yes" should be chosen.
  • Dataclasses.dbml will then be created with items inside.
  • Once the Dataclasses.dbml object has been created, click on View, then choose "Server Explorer". This will then display a window down the left hand side of the screen, showing the Database which is now available, and also the machine number currently been worked on (university only). Double click on Northwind.dbml, then open the tables.
  • Add in the required tables (this will vary for each database, but for the Northwind database add the tables requested within the tutorial). Clicking and dragging the tables across into the main view will then show the relationships between the tables added. This will create a simple ER diagram.
  • The database should now be linked in.
  • Refer back to Global.ascx and uncomment the line that starts with "//DefaultModel" at the end of the first paragraph. Uncommenting the line is done by removing the 2 forward slashes at the start of the line.
  • Go to the "typeof" section within the line and change the code within the brackets to "DataClassesDataContext".
  • Go to the end of the line and set the "ScaffoldAllTables" option to true, instead of the default "false".
  • Go to the Default.ascx file down the right hand of the screen and choose to view the page in browser - this will then display the completed file in a web page view.
  • Checking if the system works can be done by clicking on the options available, and seeing if the tables open.
  • The tables do exist, however they won't appear within the DynamicData folder down the right hand side of the screen. The tables are stored in the AppCode section of the web site, within the Database.dbml file that was created earlier.
Within last weeks tutorial I learnt how to create and mine a SQL database. This task was fairly confusing, but managed to give the correct output once completed.

To start the process I initially followed the standard steos required to create a database, including creating a New Project, linking to the SQP database, choosing C# and defining the location. This created the basic core layout for the database. Adding a new web form was the next task, followed by creating a database in the App data (this was done by right clicking on the directory name and adding a new SQL Server Database). The remaining steps are as follows:
- Choosing Server Explorer, Database Designs then right clicking on Tables and choosing "Add New Table" - this then gave me the ability to add a new table into the database.
- The next step was to add a column name and define the data type (nVarChar 50 etc.), avoiding using spaces between the words within the column title. Ant saving to the table is done automatically when the table is closed.
- Right click on table in Tables (Toolbox) and select "Show Table Data". To make changes, right click on table name and choose "Open Table Definition".
- Primary keys can be applied to a particular column name by right clicking on column name and defining it to be the primary key - this process must be done though before adding the table to the database.
- The next stage is to add a Drop Down List into the design view (it will currently be unbound).
- Choose Data Source and select a New Data Source. Choosing the SQL database is the next stage, followed by defining a connection method to the database. This connection should then be saved once defined.
- From the data source, select the "*", which will choose all column names from the table. Testing the query should then result in all the records appearing. Click Finish. State DropDown options. Click Finish. The object should now be databound.
- All connections are held within the webconfig file in the system.
- The next stage is to add a GridView from the Data option in the Toolbox. Choosing the Data Source as SqlDataSource 1 or SqlDataSource2 will provide a connection between the newly inserted option and the table.
- The names of the column headings should now be inserted into the object.
- Previewing in browser is a good text to see if it has worked.
- Select the arrow in the corner of Grid View and choose Auto Format to define a style - using a simple one is better for this exercise.
- Enable sorting (optional)
- Enable paging (optional)
- Enable selection (optional)
- Clicking on column headings will sort the order once viewed in a browser.
- Properties enable other types of formatting that can be applied to the table.
- Select the arrow in the corner of the GridView and choose ConfigDataSource, click next and then advanced, click Generate then next, and then choose WHERE > StudentID = Control > DropDownList1. Click Add, OK, Next, Test, Finish.
- These statements bring bacj information relating to ta piece of information about a student.
- Show data where students have the same piece of information in drop down list.
- Enable AutoPostBack.