Chapter 14.3 LINQ to SQL Programming in Visual Basic 2010: The Very Beginner’s Guide by Jim McKeown Databases – Part 3.

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

Customizing the MOSS 2007 Search Results November 2007 Rafael Perez.
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)
BIM211 – Visual Programming Database Operations 1.
BIM313 – Advanced Programming Database Operations 1.
1 Web-Enabled Decision Support Systems Database Connectivity with ADO.NET Prof. Name Position (123) University 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.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Integrating Access with the Web and with Other Programs.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Working with SharePoint Document Libraries. What are document libraries? Document libraries are collections of files that you can share with team members.
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
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
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.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
BİL528 – Bilgisayar Programlama II Database Operations II 1.
Chapter 15: Using LINQ to Access Data in C# Programs.
Creating a Web Site to Gather Data and Conduct Research.
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.
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.
1 Web-Enabled Decision Support Systems Database Connectivity in Web Applications Don McLaughlin IE 423 (304) West.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Thirteen Working with Access Databases and LINQ.
 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.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Access Project 7 Advanced Report and Form Techniques.
Course ILT Forms and queries Unit objectives Create forms by using AutoForm and the Form Wizard, and add or modify form headers and footers Open and enter.
Access Forms and Queries. Entering Data in Your Table  You can add data to your table in Datasheet view, by typing in the columns and rows.  This.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
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.
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.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 8 1 Microsoft Office Access 2003 Tutorial 8 – Integrating Access with the.
Understand Databound Controls Windows Development Fundamentals LESSON 4.2A.
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.
VB.NET and Databases. ADO.NET VB.Net allows you many ways to connect to a database. The technology used to interact with a database or data source is.
Access Queries and Forms. Adding a New Field  To insert a field after you have saved your table, open Access, and open the table  It is easier to add.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
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.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Visual Basic 2010 How to Program
VB 2010 Pertemuan 10.
Practical Office 2007 Chapter 10
Brief description on how to navigate within this presentation (ppt)
CIS16 Application Programming with Visual Basic
Microsoft Office Access 2003
Microsoft Office Access 2003
CIS16 Application Programming with Visual Basic
Database Applications
Accessing Databases with ADO.NET, Handling Exceptions, and Printing
Chapter 10 Accessing Database Files
Presentation transcript:

Chapter 14.3 LINQ to SQL Programming in Visual Basic 2010: The Very Beginner’s Guide by Jim McKeown Databases – Part 3

Customer Queries Sometimes there’s just too much data Queries look through a database and retrieve data that matches the search criteria Queries find records that match the search, display selected fields in the results and order the records for easy reference Use a DataGridView to demonstrate a query Query search or searches in a database; return specified fields from selected records and display them in a specific order 2

Database File for this Part We need the Customers database file See my web page. Download and open and look at it. Close it. 3

Customer Queries Create a new form Name the controls Add a DataGridView (I used a form) 4

Tasks – Build the Connections, etc. See grid in book and create form from it, if you wish. Or use the DataGridView control from the toolbox in lieu of the form and controls we’re used to. If you use controls, name Controls and Labels,… Either will be okay. Electing to do the form is a bit more work; when electing the datagridview, some things are done for you… The slides ahead are for Forms: Add Binding Source from Toolbox (Category: Data) Name it bdsCustomer in Name Property Add DataSource property via drop down…. Goto next slide 5

(except this one) If using DataGridView in lieu of Form If using DataGridView in lieu of form, there are a few differences. Here are a few… select DataGridView control. Click on play Choose Data Source can select WagesDataSetBinding Links WagesDataSet and WagesDataSetBinding in component tray Select WagesDataSetBindingSource See properties DataSource (linked to WagesDataSet) Select DataMember; select tblWages Note: grid modified and has fields. Expand. Fill form space up with grid… 6

Tasks Add Project Data Source items… Database, dataset, New Connection, Change, (Microsoft Access Database File), Browse for Database File (from desktop), Select Customers.mdb, (book says Wages. Wrong) Test Connection, OK Next, Yes, Next, Goto next slide 7

Tasks Step 10 in book, p. 588 Select Database Objects for the Data Set. we do this by expanding the Tables Checkbox click on tblCustomers. Leave checked. Finish Component Tray now includes A Customers Data Set 8

Tasks Select DataMember property of binding source (bdsCustomer) and set to tblCustomers. Adds TBLCustomersTable Adaptor to Component tray. Save Project. Onto Step 13 in book… 9

Tasks Bind the Controls to the Dataset (if using controls / form). For each control, Go to DataBindings in property window, Text properties, bdsCustomer, and associate controls to dataset objects. 10

Tasks Add Binding Navigator drag from toolbox to top of form Name it bdsCustomers via property window Link your binding navigator to your data by changing BindingSource property of the binding navigator to bdsCustomer (drop down) Run your program!! 11

On to Customer Queries Select TblCustomersTableAdapter in component tray. Select Add Query... at the bottom of the Properties window Search Criteria Builder wizard displays Select a New query name: and enter Outdoors to build a query of customers interested in the outdoors (see next slide) 12

Query Wizard looks like: 13 Customers Search Criteria Builder Added query name

Customer Queries Select Query Builder button to open the Query Builder dialog (three slides down) Top section has the fields listed for tblCustomers and all fields are selected Leave all the fields selected All fields must be selected when using the DataGridView 14

Customer Queries Second section has a list of the fields and the search criteria for it (two slides down) Build your query in this section Scroll down to the Interests field Change the Filter to = ‘Outdoors’ Modifies a query template (next slide) that looks through all the records and returns those with Outdoors as an Interest And adds the query being built in the third section See SQL next slide: 15

Customer Queries Third section now reads SELECT ID, LastName, FirstName, CustNum, Address, City, State, Zip, Since, [Last], Preferred, AcctBalance, Interests FROM tblCustomers WHERE (Interests = 'Outdoors') ADDED THE Where! WHERE clause added to the SQL statement being build Statement says to select all fields from tblCustomers and only those records where ‘Outdoors’ is in the Interests field 16

Customer Queries 17 Customers Query Builder

Customer Queries Select OK to close the Query Builder (last slide) Select OK to close the Search Criteria Builder and create your query (slide not shown) ToolStrip named OutdoorsToolStrip is added to component tray and thus your query is added! underneath Binding Navigator Run program; all records available as output Select Outdoors runs the query and it displays only those records with Outdoors listed in the Interests field 18

Customer Queries Note the Code added to the click event for the Outdoors button on the ToolStrip Try Me.TblCustomersTableAdapter.Outdoors(Me.CustomersDa taSet.tblCustomers) Catch ex As System.Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try 19

Select TblCustomersTableAdapter in component tray Select Add Query... bottom of the Properties window Displays Search Criteria Builder wizard Data source table already set Select a New query name: (I named it AllQuery) and Select Query Builder Button. (Want all, so no changes) Select OK for Query Builder (see window title too) Select OK for Search Criteria Builder (see window title) 20 Query: Select All Records. (new)

Query: AllQuery SQL stays the same. SELECT ID, LastName, FirstName, CustNum, Address, City, State, Zip, Since, [Last], Preferred, AcctBalance, Interests FROM tblCustomers ToolStrip named All added to the component try and underneath Binding Navigator strip Run the program Click Outdoors to run that query and it displays only those records in the DataGridView Click All to display all the records in your view. 21

Code added to the click event for the All button in the new ToolStrip Also added another subroutine in the code window for this query: Private Sub AllQueryToolStripButton_Click…. Try Me.TblCustomersTableAdapter.All(Me.CustomersDataSet.tblCustomers) Catch ex As System.Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try 22 Query: AllQuery

More If you want to play with these, you can get rid of a set of query toolstrips. See book. 23

Data Base Terminology - Important When a DataSet is created it generates an.xsd file View it by selecting the TableAdapter and Edit Queries in the DataSet Designer at the bottom of the Properties window Contains the XML schema XML (Extensible Markup Language): Is a specification for creating content and structure for data; XML is an open standard specification widely used as a specification language for data and the web 24

Customer Queries These documents define and validate the content and structure of your data Use to exchange data between applications Schema a diagram or plan detailing the structure of your content; for VB, it contains the structure for your DataSet 25

Customer Queries 26 Customers DataSet1 Existing Queries

VB Quiz 03 What happens if you don't select all the fields for a query? An Exception will be generated. What makes the Query Builder useful? You don’t have to know SQL. But this is limiting… How were the records sorted in the Payable query? Last Name What SQL code was needed to do it? Ordered by… 27

Potential Problems Your program won’t work if the database is corrupt Database file cannot be in use by another program Don’t delete or change code that’s automatically generated Bind your DataSet to a DataGridView or to individual controls such as a TextBox or Label Include a BindingNavigator so you can move between records Be careful when deleting controls from the component tray and Solution Explorer 28

On Your Own Take a look at Appendix G -- Structured Query Language (SQL) Basics Add queries to the Customer program Customers in your state Customers without Preferred status Customers name Ecks, Ray Customers since

On Your Own Create a program with the Customers file that displays data in TextBoxes and CheckBoxes Add controls and code to allow the user to update the database 30

Create a program with the KidsFirst file that displays data in a DataGridView Add queries to find all students in Miss Brooks class all students without a pet (look for ‘none’) all seven-year-old students all seven-year-old students in Mr. Moore’s class all students in order by LastName all students in descending order by Locker 31 Part 5; Project points

If you are smart…. You will go over the Review questions, the terms, the multiple choice questions, etc. at the end of the chapter! 32

Summary Visual Basic has controls that can link it to a database Chapter contains tutorials to demonstrate how to connect to an Access file and manipulate records in a file Database controls were introduced Simple SQL examples were introduced 33