1 / 11

Unit 3 Data Access using GUI

Unit 3 Data Access using GUI. Agenda. Data Sources SQL Data Source Displaying Data GridView DetailsView Configuration Manager Accessing Data. Data Sources. Embody a connection to a database Location Name Contain an SQL command Example: SqlDataSource is used with MS SQL Server.

zazu
Télécharger la présentation

Unit 3 Data Access using GUI

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unit 3Data Access using GUI

  2. Agenda • Data Sources • SQL Data Source • Displaying Data • GridView • DetailsView • Configuration Manager • Accessing Data

  3. Data Sources • Embody a connection to a database • Location • Name • Contain an SQL command • Example: • SqlDataSource is used with MS SQL Server

  4. SQL DataSource • It represents: • name and location of database • SQL command • Specific to MS SQL Server • Uses a wizard for configuration • Prefix: “sds”

  5. Displaying Data • Two GUI controls used for displaying data: • GridView: shows all records • DetailsView: shows selected record • Need to be bound to a Data Source, such as • SQLDataSource • DataReader • Customizable • See note on Design in Unit 3.1 Step-By-Step

  6. GridViews • Show all records of a dataset • Can do more than display • Paging • Sorting data • Insert, Update functions • Custom Template Fields

  7. DetailsView • Show only a single record at a time • Supports inserting and updating similar to GridViews • Often paired with GridViews

  8. Configuration Manager • Web applications need governing rule-sets • For login controls, web services, or databases • They exist as web.config files in ASPPub • For Databases  Connection Strings • Store path, database filename, database driver • Example: (Can you tell the “name” of the connection string?) <configuration> <connectionStrings> <add name="Products" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SouthBreezeGroceries.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/> </connectionStrings> <other-web-service-stuff> </other-web-service-stuff> </configuration>

  9. Accessing Data: Create a GridViewRow • GridViews are collections of rows. • So your code needs to loop through these rows • First, create an object of the type GridViewRow GridViewRowGrvCheck GridViewGrvOrders

  10. Accessing Data: Setup the loop • Setup a loop to go through all rows • The FOREACH loop is a variation of the FOR loop • It can automatically cycle through rows. • For example: foreach (GridViewRowgrvCheck in grvOrders.Rows) { // do stuff for one row at a time // collect all data, do any totals }

  11. Accessing Data: Working with cells • Each row has many columns, or cells. • Cells are indexed (counting from zero). • In the example below: • The first column, i.e. Column 0 is occupied by the Select button • The second column contains OrderID. Since indices begin at 0, the second column is accessed by the index of 1, as shown below: OrderID = Convert.ToInt32(grvCheck.Cells[1].Text); grvCheck.Cells[1].Text

More Related