CIS16 Application Programming with Visual Basic

Slides:



Advertisements
Similar presentations
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Advertisements

 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 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.
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 ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Some Basic Database Terminology
Chapter 2: Working with Data in a Project
Databases and LINQ Visual Basic 2010 How to Program 1.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
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.
Lesson 2.  To help ensure accurate data, rules that check entries against specified values can be applied to a field. A validation rule is applied to.
Lesson 17 Getting Started with Access Essentials
Key Applications Module Lesson 21 — Access Essentials
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
1/62 Introduction to and Using MS Access Database Management and Analysis Yunho Song.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
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.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
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.
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.
Creating SQL Database file And Displaying a Database Table in a DataGridView.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
COMPUTER SKILLS MS-ACCESS. Introduction Access is a piece of software known as a database management system. At its most basic level, it can be used to.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Visual Basic 2010 How to Program
Databases and SQL Designing a database with tables and primary keys
GO! with Microsoft Office 2016
Access Tutorial 1 Creating a Database
Practical Office 2007 Chapter 10
Basic Database Concepts
© 2013, Mike Murach & Associates, Inc.
GO! with Microsoft Access 2016
Access Creating a Database
Access Creating a Database
CIS 155 INTRODUCTION TO ACCESS 2002
Access Lesson 1 Understanding Access Fundamentals
Access Tutorial 1 Creating a Database
MODULE 7 Microsoft Access 2010
Brief description on how to navigate within this presentation (ppt)
CIS16 Application Programming with Visual Basic
Access Lesson 2 Creating a Database
Access: Access Basics Participation Project
Chapter 1 Databases and Database Objects: An Introduction
Microsoft Office Access 2003
Database Applications
Access Tutorial 1 Creating a Database
Chapter 10 Accessing Database Files
Access Tutorial 1 Creating a Database
Unit J: Creating a Database
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

CIS16 Application Programming with Visual Basic Chapter Eleven SQL Server Databases

Database Terminology Computer database An electronic file that contains an organized collection of related information Popular databases Microsoft Access Microsoft SQL Server Oracle Interface DBMS Computer program

Database Terminology Relational database Stores information in tables composed of columns and rows, similar to the format used in a spreadsheet Information can be related in different way Table A group of records Records A group of related data (fields)

Database Terminology (cont'd.) Primary key A field that uniquely identifies each record Parent and Child tables Tables related to each other through a common field Foreign key The field in the child table that matches the field in the parent table Example of a two-table relational database

Connecting an Application to a Database Data accessed from the database

CREATING A SQL SERVER DATABASE USING VISUAL STUDIO

Step 1: Defining the Database Click Project->Add New-> Service-based database & specify the name of the SQL SERVER database in the NAME textbox

Step 2:Verification In the Solution explorer, the MDF file will appear.

STEP 3: Server Explorer Right click the MDF file and choose open, to open the SERVER EXPLORER Window

Creating Database objects Or..open the SERVER EXPLORER, expand DATA CONNECTIONS, and EXPAND THE DATABASE, to see its OBJECTS To create a table, right click TABLES in the server explorer and choose ADD NEW TABLE

Creating tables in Server Explorer Table designer opens with a new empty table

Creating Table fields in Server Explorer Two most important properties for field are: Name: identifies field Data Type: designates type of information that an be stored in the field Defining fields Choose a data type that minimizes the amount of storage needed for the data Indicate if field can store a null value (no entry) Indicate default values Indicate identity fields – automatically generated; assign seed or increment Indicate constraints – ex. Data in field must be > 100

SQL Server data types Bit Char, varchar, text Boolean – value of 0 or 1, true or false Char, varchar, text Any combination of letters, symbols, numbers Date, time, datetime, smalldatetime Represents a date &/ time Decimal, numeric: numeric data integer and fractional portion Float, real decimal Bigint, int, smallint, tinyint numeric data with only the integer portion Money, smallmoney currency accurate to 4 decimal places

Creating tables in Server Explorer Begin adding fields and field properties To set a compound key, modify the TSQL Be sure to give your table a good name before saving your SQL and before clicking the UPDATE button

Creating tables in Server Explorer Click UPDATE BUTTON to PREVIEW THEN CLICK UPDATE DATABASE TO ADD TABLE

Creating tables in Server Explorer THE OPERATIONS WINDOW WILL DISPLAY THE STATUS OF THE UPDATE

Creating tables in Server Explorer When complete, refresh, and the Server Explorer displays the table Expanding the table will display its fields Selecting a field will display its properties in the properties pane Right click the table and select “OPEN TABLE DEFINITION” to redisplay the TABLE DESIGNER window

Relationships Associates rows of one table with rows of another To create a foreign key relationship in Table Designer Open the FOREIGN KEY TABLE in Table Designer In the Foreign-key Relationships dialog box, right-click and choose Add new Relationship. Replace the placeholders in the script pane Click UPDATE to change the table and add the relationship https://msdn.microsoft.com/en-us/library/hh272679(v=vs.103).aspx

Adding Data to a table Right-Click the table and choose SHOW TABLE DATA Begin adding records If you try to add a record that violates the foreign key, an error will occur!

Connecting an application to a SQL SERVER database

Connecting an Application to a Database Before a software application can access the data is a table, it must connect to the database Then, it must define the source of data Data source connection wizard Specify the data you want to access Computer makes a copy of that data and stores the copy in memory as a dataset Allows you to also test that the connection works

Data Source Wizard dsadsa

Selecting the database Specify the database which the data source will use

Saving the connection information Click to save all of the information

Table selection Next select the tables and fields which will be used in this data source

Finished Data source The data source has created the data set definition and saved it in a DataSet file. Test it by right-clicking the Data Set and choose Preview Data

App.config connection Connection is defined in hidden file, app.config

Testing the data set Right click data set in data source pane and choose Edit dataset with Designer

Testing the data set Right click the table name in the Date source pane and choose Preview Data

Testing the data set Click Preview button

BINDING TO THE DATA SOURCE

Binding the Objects in a Dataset (cont'd.) Connecting a dataset to a control on the form Connected controls are called bound controls The TableAdapter object connects the database, retrieves the appropriate information, and stores it in the DataSet object A bound control can then access the data using the BindingSource object

Binding the Objects in a Dataset (cont'd.) 5 objects in component tray Dataset BindingSource TableAdapter TableAdapterManager Binding Navigator

Ways to bind data Automatically create bound controls by dragging the dataset onto the form If controls already exist, bind by dragging a field in the data set onto the existing control When controls are bound, the form_load procedure has code written to it automatically to connect to the dataset

Automatically create the bound control

EX 1:Automatically Create Bound Controls (method 1) Drag a field or the table from a dataset to an empty area on the form

EX 1:Automatically Create Bound Controls (method 2) Drag the Table Object to the form Creates a DataGridView control and a binding navigator control The DataGridView control displays the data in a format similar to a spreadsheet The BindingNavigator control is used to move from one record to the next in the dataset, as well as to add or delete a record and save any changes made to the dataset

EX 1:Automatically Create Bound Controls (method 3) To display data in separate textboxes rather than DataGrid, click on Details and drag table by name onto form

Binding to an existing control Microsoft Visual Basic 2012: Reloaded, Fifth Edition Binding to an existing control

Ex 2: Drag a data field onto an existing control Fewer data objects in the system tray

Ex 2: Drag a data field onto an existing control (cont) Drawbacks Navigation toolbar is not automatically created Dragging to existing control does not add a BindingNavigator object to the component tray Doesn’t add a BindingNavigator control to the form

Ex 2: Drag a data field onto an existing control(cont) To create navigation toolbar manually add a BindingNavigator control and object to the application

Ex 2: Drag a data field onto an existing control (cont'd.) Set the control’s DataSource property to the name of the BindingSource object in the Items Collection Editor

Ex 2: Drag a data field onto an existing control (cont'd.) Alternative is to code the Next Record and Previous Record buttons to view the remaining records, using BindingSource component in the component tray

Ex 2: Drag a data field onto an existing control (cont'd.) The BindingSource object uses an invisible record pointer to keep track of the current record in the dataset Pointer is stored in Position property, starting at 0 Can set position to move to record

Ex 2: Drag a data field onto an existing control (cont'd.) Can use the BindingSource object’s Move methods

Ex 2: Drag a data field onto an existing control (cont'd.) When user clicks next record button, procedure should move record pointer to next record

DataGridView control

DataGridView control Most popular, as can view lots of information at a glance Displays the data in a row and column format Each row represents a record, and each column represents a field The intersection of a row and a column in a DataGridView control is called a cell

DataGridView control Drag DataViewGrid control onto form Open smart tag, choose data source If the project data sources isn’t displaying, choose add project data source, and complete the wizard

DataGridView control (cont'd.) DataGridView control has a task list

DataGridView control Edit Columns used to improve appearance Add or remove columns from DataGrid Resequence controls Set properties of bound control in Datagrid Cell style, width, alignment, etc. Can change the heading for the column

Binding navigator control Microsoft Visual Basic 2012: Reloaded, Fifth Edition Binding navigator control

Personalizing a Binding Navigator Control BindingNavigator control contains buttons that allow you to move to a different record in the dataset, add or delete a record, and save any changes made to the dataset Might want to include additional items on the BindingNavigator control another button, a text box, or a drop-down button Code is automatically written for binding navigator events

Customizing a Binding Navigator Control Click the binding navigators task box to choose the item to add

Customizing a Binding Navigator Control (cont'd.) DropDownButton added to the BindingNavigator control Double-click to write code for new navigation item

Connecting an application to aN ACCESS database

Connecting an Application to a Microsoft Access Database (cont'd.)

Connecting an Application to a Microsoft Access Database (cont'd.)

The Copy to Output Directory Property Data Source configuration added database to project Referred to as a Local database At run time, database in bin/debug folder is used Will have 2 copies of the database Copy to Output directory property determines how changes are saved to database