Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.

Similar presentations


Presentation on theme: "Introduction to ADO.Net and Visual Studio Database Tools ISYS 350."— Presentation transcript:

1 Introduction to ADO.Net and Visual Studio Database Tools ISYS 350

2 Database Processing Querying database Updating database: –Insertion, deletion, modification

3 Steps to Retrieve Data Establishes a connection to the database. Executes query commands against the database. –SQL Select commands Process the returned data.

4 Steps to Update Data Establishes a connection to the database. Executes update commands against the database. –SQL Insert, Delete, Update commands Receive confirmation of completion.

5 ADO.Net Classes and Data Consumer Ado.Net Connection Adapter Command DataReader Dataset Data Consumer WinForm WebForm

6 ADO.NET Objects Connection Object: Represent a connection to the database. Command Object: The command object allows us to execute a SQL statement or a stored procedure. DataReader: It is a read-only and forward-only pointer into a table to retrieve records. DataSet Object: A DataSet object can hold several tables and relationships between tables. DataAdapter: This the object used to pass data between the database and the dataset.

7 SQL Server Express LocalDB SQL Server Express LocalDB is a light- weight version of SQL Server Express that is already installed with VS 2012, and it does not bring heavy workload on development machines

8 Lab: Creating a LocalDB Database 1. Start SQL Server Express LocalDB: –View/SQL Server Object Explorer –Click and open: SQL Server

9 Lab: Creating a LocalDB Database Database Name: MyHR Table: –Employee EID: NCHAR(5) Ename: NCHAR(20) Sex: NCHAR(1) Salary: Numeric(9,2) HireDate: Datetime

10 To Add a New Database Open the LocalDB node Right-click Databases –Add new database Enter database name –Example: MyHR

11 To Add a New Table: Employee Open the Database node: Open the MyHR node Right-click Tables and select: Add New Table Change the table name to Employee –CREATE TABLE [dbo].[Employee] Define fields Click Update: –click Update Database

12 To Add Records Open the Tables node Right-click the table name (Employee) and select View Data

13 To Modify Table Design Point and right-click the table name: –Select: View/Designer Change the CREATE TABLE command Or Change the design with the designer

14 Data Binding Connect a control or property to one or more data elements. Simple binding: Use simple binding to display a field value in controls that show Data Bindings in the property window, such as text box or label. Complex binding: Use complex binding to bind more than one field to controls such as DataGrid and list box. Use the control’s Data Source and Data Member to bind the data.

15 Generating Data Bound Form with Form Wizard Creating a form with ADO.Net objects and data- bound controls to display and update information in a dataset. Step 1: Add a connection to the LocalDB database. Step 2: Add a new data source: Step 3: Select controls for table fields: –Click the dropdown list next to the table’s name: Datagrid view Details Step 4: Drag the table to form.

16 Add a Connection to LocalDB Database Tools/Connect to database –Click Change –Click Microsoft SQL Server: Enter Server Name: –(localdb)\Projects –Or, (localdb)\v11.0 Log on to server: –Using Windows authentication Select or enter a database name –Test Connection

17 Add a New Data Source Data Source window: –View/Other windows/Data Source Add New Data Source –From Database –From Dataset –Select connection –Select tables

18 Data Bound Form Examples Using the LocalDB database MyHR, show records of the Employee table: –with dataGridView –with detail view

19 Items Added to the Form Table Adapter: click smart tag –Add query –Preview data Dataset: Binding Source: It is an object that keeps track of position (the current row) of a data source. –Preview data

20 Other Data Form Demos DataGrid View Add /Modify/Delete records. Read only form: –Delete AddNew, Delete, Save buttons from navigator bar.

21 Detail Form with Bound ListBox Example: Employee table form with EID listbox and displays selected employee information in textboxes. –Choose detail view for the Employee table. –Click the dropdown list next to the EID field and click ListBox –Drag the Employee table to the form. –Bind the EID field to the BindingSource: Activate the Property window and click the listbox Set the DataSOurce property to BindingSource Set the Display Member property to EID

22 Add an Dependents Table to the MyHR Database Dependents table: –DependentID: NCHAR(5) –DepName: NCHAR(20) –DepRelationship: NCHAR(15) ----- Spouse/Son/Daughter –EID: NCHAR(5) Open the Database node: Open the MyHR node Right-click Tables and select: Add New Table Change the table name to Dependents CREATE TABLE [dbo].[Dependents] Define fields Click Update; then click Update Database

23 Hierarchical Forms: Employee/Dependents Parent table/Child table –Add parent table and child table to Data Source –Drag the parent table and the child table to the form. Parent table uses detail view and child table uses dataGrid view –Click Dataset object’s smart tag to choose Edit in Dataset Designer –With the designer, right click the parent table and choose Add/Relation –Change dataGrid’s DataSource property to the relation.


Download ppt "Introduction to ADO.Net and Visual Studio Database Tools ISYS 350."

Similar presentations


Ads by Google