Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.

Slides:



Advertisements
Similar presentations
Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
Advertisements

Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
 Open the Paradise.exe file  Application displays records in the Books database  Allows the store manager to enter an author’s name (or part of a name)
Chapter 14.3 LINQ to SQL Programming in Visual Basic 2010: The Very Beginner’s Guide by Jim McKeown Databases – Part 3.
1 Web-Enabled Decision Support Systems Advance Topics in Database Connectivity Prof. Name Position (123) University Name.
Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Using ADO.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
Introduction to Data Adapter. A Simplified View of ADO.Net Objects Ado.Net Data Provider Connection Adapter Command Reader Dataset Data Consumer WinForm.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
C# Programming: From Problem Analysis to Program Design1 Working with Databases C# Programming: From Problem Analysis to Program Design 3 rd Edition 14.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
Some Basic Database Terminology
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
Databases and LINQ Visual Basic 2010 How to Program 1.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
BIM211 – Visual Programming Database Operations II 1.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Advanced Visual Basic th Edition Chapter 3: Using SQL Server Databases (c) 2007 Pearson Education Inc. All rights reserved. You may modify and copy.
® Microsoft Office 2013 Access Building a Database and Defining Table Relationships.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
1 Databound Controls. 2 Objectives You will be able to use design time data binding to display and update SQL Server database data without writing any.
Neal Stublen Populating a Database  SQLExpress should be installed with Visual Studio  The book provides a.sql file for populating.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Thirteen Working with Access Databases and LINQ.
Connecting to Data Sources Using ADO.NET Dr. Awad Khalil Computer Science & Engineering Department AUC.
 2006 Pearson Education, Inc. All rights reserved Database, SQL and ADO.NET.
CIS 338: Using Queries in Access as a RecordSource Dr. Ralph D. Westfall May, 2011.
® Microsoft Office 2010 Building a Database and Defining Table Relationships.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
Using Adapter Wizard ISYS 512. Data Adapter Wizard – 2 nd Level of Using ADO.Net Configure Data Adapter and generating a dataset: –From the Data tab of.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
Databases with LINQ. LINQ to SQL LINQ to SQL uses LINQ syntax to query databases. LINQ to SQL classes are automatically generated by the IDE’s LINQ to.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 12 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 12 Accessing.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload.
1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.
Chapter 24 I’m Suffering from Information Overload (Access Databases) Clearly Visual Basic: Programming with Visual Basic nd Edition.
1 Database Programming with ADO.NET Kashef Mughal.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Understand Databound Controls Windows Development Fundamentals LESSON 4.2A.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
CS 281 – Fall 2010 Lab 4 Parametric Query and Forms in MS Access.
Creating SQL Database file And Displaying a Database Table in a DataGridView.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Copyright © 2014 Pearson Canada Inc. Ext. 5b-1 Copyright © 2014 Pearson Canada Inc. Application Extension 5b Using Microsoft Access Part 2: Using Information.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Access Tutorial 2 Building a Database and Defining Table Relationships
Database, SQL and ADO.NET
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Visual Basic 2010 How to Program
© 2013, Mike Murach & Associates, Inc.
Brief description on how to navigate within this presentation (ppt)
CIS16 Application Programming with Visual Basic
CIS16 Application Programming with Visual Basic
Database Applications
Chapter 10 Accessing Database Files
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query How to use the Dataset Designer How to generate detail controls from a data source How to use Query Builder to build more complicated parameterized queries

How to create a data source Data Source specifies the source of the data for the application most apps get their data from a database Data source window shows all tables and columns in the dataset that are available to the application. display by clicking on Data Sources tab at left edge display by selecting Data > Show Data Sources If no data sources available, click on Add New Data Source link. Starts the Data Source Configuration Wizard Actually 4 different ways to start this Wizard (pg. 544) 2

3 display by selecting Data > Show Data Sources

4

If you add a database file to your project By default, that file is copied to the output directory for the project every time the project is built When you run the app, it works with the copy of the database file in the output directory Any changes made to the database aren’t applied to the database file in the project directory Each time you rebuild, database in output directory is overwritten Change this, by selecting database file in Solution Explorer and change its “Copy to Output Directory” property to “Copy if newer” 5

Choosing the connection for the data source Can choose from a previously defined connection Or click New Connection Click the Connection string button to make sure you have the right connection 6

Creating a connection to a database How you do this differs for SQL Server Express (default) Microsoft Access using a database server running on a network server etc. WE ARE USING MICROSOFT ACCESS – NO WHINING!!! Change the data source to Microsoft Access Database File Enter the database filename Click Test Connection to be sure connection is configured properly Save the Connection string in the app configuration file Now table adapters that use the connection can refer to the connection string by name 7

8

Choosing database objects for a data source Last step of the Data Source Configuration Wizard Choose any tables, views, stored procedures, functions available from database Can expand nodes and just choose columns Can also enter the name you want to use for the dataset Default: databasename + “DataSet” NOTE: selection of several tables in the dataset, maintains the relationships between those tables 9

10

Schema file After completing Data Source Configuration Wizard new data source is displayed in Data Sources Window generates a file that contains the schema for the DataSet class defines the structure of the dataset, incl. tables and columns it contains, data types, and constraints listed in Solution Explorer Window with extension. xsd double- click it to view graphic representation generated code is below it when you create bound controls from the data source, the code in this class is used to define the DataSet object that the controls are bound to – DO NOT CHANGE THIS CODE! 11

12 Schema file, generated code file for DataSet

How to use a data source Bind controls to the data source and then use the bound controls to add, update, and delete the data in the datasource. We’ll use DataGridView and TextBox controls in our examples. Steps Drag a table from the Data Sources Window onto a form adds a DataGridView control to the form and binds it to the table - allows browsing of rows, as well as add, update and delete rows (complex data binding) adds five more objects to the Component Designer tray 13

14

Objects in Component Designer Tray DataSet – defines the dataset that contains the Authors table TableAdapter – provides command that can be used to work with the Authors table TableAdapterManager – provides for writing the data in two or more related tables to the database, so referential integrity is maintained BindingSource - specifies the data source (the Authors table) that the controls are bound to and provides functionality for working with the data source BindingNavigator – defines the toolbar that contains the controls for working with the data structure 15

Generated code When application starts, the first event handler is executed it uses the Fill method of the TableAdapter object to load data into the DataSet object because the DataGridView control is bound to this table, the data is displayed in this control 16 private void Form1_Load(object sender, EventArgs e) { this.authorsTableAdapter.Fill(this.booksDataSet.Authors); }

Generated code When user changes the data in the DataGridView control changes are saved back to the dataset changes are not saved to database until user clicks the Save button calls Validate method calls EndEdit method of the BindingSource – apply any pending changes to the dataset (added/updated rows are not saved until you move to another row calls UpdateAll of the TableAdapterManager – saves the data in the DataSet object to the database (only updates rows that need updating maintaining referential integrity) 17

Generated code user clicks the Save button 18 private void authorsBindingNavigatorSaveItem_Click(object sender, EventArgs e) { this.Validate(); this.authorsBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.booksDataSet); }

How to use Query Builder DataSource Configuration Wizard doesn’t give you enough flexibility, e.g., can’t join data or sort Query Builder provides a graphical interface that you can use to modify a Select statement without knowing proper SQL syntax Steps: Select the table adapter that contains the query Right click Add query, Change query name if a new query Click Query Builder 19

Type new name for query Click Query Builder 20

21 Diagram Pane right click to add tables to pane Grid Pane shows all columns selected SQL Pane Results Pane

22

How to use the Dataset Designer Lets you work with a dataset schema using a graphic interface To view the schema – double-click on the schema file for the dataset (. xsd file) Properties you can view table adapter, query, columns in a table Example: Fix the autoincrement of the authorID column in the Authors table 23

Generating detail controls from a data source DataGridView may not be appropriate for app Can bind columns of data source to individual controls (simple data binding) Select Details option from drop-down list when you select the table in Data Sources Window Drag the table onto the form Generates a label and a bound control for each column most string/numeric columns  TextBox Change to other appropriate types by selecting column in Data Sources Window and the select a different type of control from drop-down list 24

25

26