ASP.NET Essentials & Database Programming
This content covers essential ASP.NET database programming concepts including handling route parameters, file paths, C# code for order pages, and web sitemaps for shopping carts. Learn about receiving route parameters, using file paths, improving C# code for order pages, and creating web sitemaps for efficient navigation. Understand the basics of relational databases and how to work with tables, records, primary keys, and foreign keys. Dive into the world of ASP.NET essentials and database programming with practical insights and examples.
Uploaded on Mar 06, 2025 | 0 Views
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
ASP.NET Essentials & Database Programming Presented BY: Nick Dunn Nick Dunn Presentation ID: 20 20
Contents Route Parameters File Paths Code for the Orders Page Changes for web.sitemap Tables Relationships Columns Halloween Database
Route Parameters How to receive a route parameters: Retrieve parameters from a friendly URL using Values collection of the page s RouteData property: string catID = RouteData.Value[ catID ].ToString(); Retrieve URL parameters from outside of the web page, use RequestContext property to get the RouteData property: string catID = HttpContext.Current.Request.RequestContext.RouteData.Values[ catID ].ToString();
File Paths 3 techniques to make file paths relative to root directory: / <link href= /Styles/Order.css rel= stylesheet /> Server control: ~ <asp:Image ID= image1 ImageUrl= ~/Images/banner.jpg /> HTML element: ResolveURL method + ~ <img src= <%=ResolveURL( ~/Images/banner.jpg )%> />
C# code for Order page Problem when a user selects a new product in the drop-down list posts back to the page. If user selects Hippie from the list, the Hippie data will be displayed but the URL will still be /Shopping/Order/cat01
Improved C# code for the Order Page Page_Load: if (routeProductID == ) AddProductIdToUrlAndRedirect(); private void AddProductIdToUrlAndRedirect() { Response.Redirect( ~/Shopping/Order/ + ddlProducts.SelectedValue); }
Web.sitemap for Shopping Cart Traditional URLS: <siteMapNode url= ~/Default.aspx title= Home > <siteMapNode url= ~/Shopping.aspx title= Shopping > <siteMapNode url= ~/Order.aspx title= Order Products > ASP.NET routing: <siteMapNode url= ~/Home title= Home > <siteMapNode url= ~/Shopping title= Shopping > <siteMapNode url= ~/Shopping/Order title= Order Products >
Database Programming Basics of relational database: A relational database uses tables to store and manipulate data Tables consists of one or more records, or rows, that contain the data for a single entry Each row contains one ore more fields, or columns, each representing a single item of data Primary key is one or more columns that can uniquely identify each row in a table A primary key that consists of two or more columns is a composite primary key Foreign keys identify a related row in another table Indexes provide an efficient way to access rows in a table based on the values in one or more columns
How tables in a database are related Relationships exist between the primary key in one table and the foreign key in another table In SQL Server, relationships can also exist between a unique key in one table and a foreign key in another table One-to-many relationships are the most common If a table has a one-to-one relationship with another table, the data in the two tables can be stored in a single table Many-to-many relationships are usually implemented by using an intermediate table, called a linking table, that has a one-to-many relationship with the two tables
Relationship between Categories and Products tables
How columns in a table are defined Two most important properties: 1. Name 2. DataType Additional properties: null value, default value Check Constraint defines the acceptable values for a column. After the constraints are defined, they re managed by the DBMS and will send an error code back to the application without adding the row to the database. Alternatively, validate data in the program before adding it to the database
Design of Halloween Database Purpose of the database is to track orders placed at an online Halloween products stores Need to track invoices, products and customer Central table is the Invoice table Products and Categories tables work together to store information about the products offered Products table has one row for each product Customers table contains a row for each customer who has purchased from the Halloween Store