210 likes | 602 Views
Some Basic Database Terminology. A relational database is data represented as a set of tables. The tables can be viewed like a spreadsheet Records (rows) — data for one item or transaction Fields (columns) — represent different elements of data
E N D
Some Basic Database Terminology • A relationaldatabase is data represented as a set of tables. • The tablescan be viewed like a spreadsheet • Records (rows) — data for one item or transaction • Fields (columns) — represent different elements of data • Key field is a field that uniquely identifies the record
XML • Data stored in XML is text, identified by tags — similar to HTML tags that can be edited by any text editor program. But the tags in XML are not predefined as they are in HTML. <course> <id>Comp 185</id> <name>Visual Basic .NET</name> <instructor>Rick Bournique</instructor> </course> • The XML needed for accessing databases will be automatically generated in Visual Basic. • ADO.NET can treat the XML data as objects, allowing the IntelliSense feature of the VS.NET environment to provide information to the programmer.
Visual Basic and Databases • VB .NET uses ADO.NET for database access. • ADO.NET is the next generation of Microsoft’s database technology,, ActiveX Data Objects (ADO). • Using ADO.NET you can display data from a database on a windows form or a web form • Using ADO.NET you can add controls to a form and bind data to them, e.g., a Label or TextBox • Some special controls are designed just for data e.g., DataGrid or DataList • An advantage of ADO.Net is that information is stored and transferred in Extensible Markup Language (XML).
Data Access in Visual Basic the DataGridView control is bound to a table in a dataset. The data fields display automatically in the cells of the grid. • You can drag tables and fields from the window onto a form to automatically create controls that are bound to the data. E.g., • Data can also be displayed in individual fields, referred to as details. • You can drag a field from the Data Sources window and drop it on an existing control — causes data binding to be set up automatically.
Steps to Display Data in Controls on a Form • Binding Source objects are automatically creates with a wizard. • Table Adapters transfer data back and forth via XML. • Datasets are disconnected in ADO.NET; the copy of data kept in memory is temporary and does not keep an active connection to the data source..
The Database Schema File • When a new data source is added to a project, a file .xsd is added to the Solution Explorer — the XML schema definition. • The schema shows the names of the table(s) and fields, the primary keys for each table, and the relationships among the tables. • Binding Source, Table Adapter, and Data Set objects are added to the form’s component tray.
Binding Individual Data Fields • Controls that are connected to fields are bound controls or data-bound controls. • Easiest way to create bound controls is to use the automatic binding feature of the Data Source window. Automatic binding creates individual text box controls for each field of data and navigation controls allowing the user to more from one record to another. • As the user clicks the navigation buttons, all controls change to display the data for the next record.
Example 1 • Let’s proceed step by step through the text example to create the R’nR Books Details View VB application.
Example 2 • Let’s modify the previous example in a couple of ways to demonstrate other concepts: • Rather than using navigation controls, change the project to use a combo box for the ISBN field (the key). We will fill the ComboBox control with values from the database . The corresponding data elements fill the remaining fields. • Rather than using the entire Books table, change the project to use only a few fields from the table.
LINQ • Language Integrated Query (LINQ), is ageneral purpose query language that can ask a question of any data that is defined as an object (e.g., a collection from a listbox), a database, or as XML. • VB contains a LINQ to SQL component to convert database items to objects and a LINQ to XML component for converting XML document collections to objects. • The general form is: Dim Variable = From Item In Object Where SelectionCriteria Select Subitems