Post on 14-Feb-2016
description
transcript
ADO.NET FUNDAMENTALSBEGINNING ASP.NET 3.5 IN C#
WHAT IS ADO.NET
• ADO.NET is the technology that .NET applications use to interact with database.
• Data binding is a powerful and practical feature
• Not easy, must have solid grasp of ADO.NET fundamentals
UNDERSTANDING DATA MANAGEMENT
THE ROLE OF THE DATABASE
• Adding database to VS2013
ADO.NET BASICS
TWO GROUPS OF CLASSES
• Contain and manage data
• DataSet, DataTable, DataRow, and DataRelation
• Generic
• Connect to specific data source
• Connection, Command, and DataReader
• Data providers
DATA NAMESPACES
DATA PROVIDER CLASSES
• Data classes can’t accomplish much
• Data access is needed see table below
DIRECT DATA ACCESS
• The easiest to connect to the database
• Steps1. Create Connection, Command, and DataReader objects.
2. Use the DataReader to retrieve information from the database, and display it in a control on a web form.
3. Close your connection.
4. Send the page to the user. At this point, the information your user sees and the information in the database no longer have any connection, and all the ADO.NET objects have been destroyed.
To add or update information, follow these steps:
5. Create new Connection and Command objects.
6. Execute the Command (with the appropriate SQL statement).
NAMESPACES NEEDED
using System.Data;
using System.Data.SqlClient;
CREATING A CONNECTION
• SQL Server through the OLE DB provider
• Using SqlConnection object from the SQL Server
THE CONNECTION STRING
• Data source – name of the server
• Initial catalog – name of the database
• Integrated security – using Windows user account, SSPI (security support provider interface) or SQL server user id and password
• Connection Timeout – how long your code will wait before generating an error
STORING THE CONNECTION STRING
• Using a constructor
• Store in web.config
• Import it
GRIDVIEW EXAMPLE WITH MDF FILE
Drag GridView
Bind a data source
Download the file from douap.uap.asia
The name to be added in the web.config
Shows the columns of the database table
Test the connection
Adding/modifying the properties
• Adding theme and AutoGenerateEditButton="true"
EXERCISE
• Add insert to the GridView
• Add UpdateCommand
• Add DeleteCommand
PROBLEM SET
• Modify the order menu to use mdf files and add CRUD