Module 3 Visual programming
Module 3 Visual programming
An introduction to database programming - Introduction to relational database, how to use SQL to work
with data in database. Introduction to ADO.NET 4. How to use SQL data source, how to use custom
statements and stored procedures, Data list controls, Data binding, advanced features of a SQL data
source.
• Each table consists of one or more records, or rows or tuple, that contain the data for a single entry.
• Each row contains one or more fields, or columns or attributes , with each column representing a
single item of data.
• Most tables contain a primary key that uniquely identifies each row in the table.
• The primary key often consists of a single column, but it can also consist of two or more columns.
• If a primary key uses two or more columns, it’s called a composite primary key.
• In addition to primary keys, some database management systems let you define one or more non-
primary keys.
• In SQL Server, these keys are called unique keys, and they’re implemented using unique key
constraints. Like a primary key, a non-primary key uniquely identifies each row in the table.
• A table can also be defined with one or more indexes. An index provides an efficient way to
access data from a table based on the values in specific columns. An index is automatically
created for a table’s primary and non-primary keys.
RELATIONSHIP BETWEEN TABLES
• The tables in a relational database are related to each other through their key columns. For example,
the CategoryID column is used to relate the Categories and Products tables above. The CategoryID
column in the Products table is called a foreign key because it identifies a related row in the Categories
table.
• Usually, a foreign key corresponds to the primary key in the related table. In SQL Server, however, a
foreign key can also correspond to a unique key in the related table.
When two tables are related via a foreign key, the table with the foreign key is referred to as the foreign
key table and the table with the primary key is referred to as the primary key table.
• The relationships between the tables in a database correspond to the relationships between the
entities they represent.
The most common type of relationship is a one-to- many relationship as illustrated by the Categories
and Products tables. A table can also have a one-to-one relationship or a many-to-many relationship
with another table.
HOW THE COLUMNS IN A TABLE ARE DEFINED
• The data type that’s assigned to a column determines the type of information that can be stored in the
column. Depending on the data type, the column definition can also include its length, precision, and
scale.
• Each column definition also indicates whether or not the column can contain null values. A null value
indicates that the value of the column is not known.
• A column can be defined with a default value. Then, that value is used for the column if another value
isn’t provided when a row is added to the table.
• A column can also be defined as an identity column. An identity column is a numeric column whose
value is generated automatically when a row is added to the table.
• To restrict the values that a column can hold, you define check constraints. Check constraints can be
defined at either the column level or the table level.
QUERY A SINGLE TABLE
• The result of a Select statement is a result table, or result set, like the one shown
above. A result set is a logical set of rows that consists of all of the columns and
rows requested by the Select statement.
• A result set can include calculated columns that are calculated from other
columns in the table.
• To select all of the columns in a table, you can code an asterisk (*) in place of the
column names. For example, this statement will select all of the columns from the
Products table:
Select * From Products
JOIN OPERARTION
• A join lets you combine data from two or more tables into a single result set.
• The most common type of join is an inner join. This type of join returns rows
from both.
Tables only if their related columns match.
ADD,UPDATE,DELETE COMMANDS
• You use the Insert, Update, and Delete statements to maintain the data in a
database table.
• The Insert statement can be used to add one or more rows to a table. Although
the syntax shown above is for adding just one row, there is another syntax for
adding more than one row.
• The Update and Delete statements can be used for updating or deleting one or
more rows in a table using the syntax shown above.
INTRODUCTION TO ADO.NET. NET4
ADO.NET (ActiveX Data Objects for .NET) is a set of classes in the .NET Framework
designed for data access. It provides a way for developers to interact with data
sources, such as databases. ADO.NET allows you to connect to databases, execute
queries or stored procedures, and retrieve and manipulate data.
• ADO.NET uses two types of objects to access the data in a database: datasets,
which can contain one or more data tables, and .NET data provider objects, which
include data adapters, commands, and connections.
• A dataset stores data from the database so it can be accessed by the application.
The .NET data provider objects retrieve data from and update data in the
database.
• To retrieve data from a database and store it in a data table, a data adapter
object issues a Select statement that's stored in a command object. Next, the
command object uses a connection object to connect to the database and retrieve
the data. Then, the data is passed back to the data adapter, which stores the data
in a table within the dataset.
• To update the data in a database based on the data in a data table, the data
adapter object issues an Insert, Update, or Delete statement that's stored in a
command object. Then, the command object uses a connection to connect to the
database and update the data.
• The data provider remains connected to the database only long enough to
retrieve or update the specified data. Then, it disconnects from the database and
the application works with the data via the dataset object. This is referred to as a
disconnected data architecture.
ADO.NET 4 CLASSES
• To create a SqlDataSource control, drag the control from the Data group of
the Toolbox onto the form. Then, choose Configure Data Source from the
control’s smart tag menu and proceed from there.
HOW TO USE CUSTOM STATEMENTS AND STORED PROCEDURES
• To use custom statements with a SQL data source, select the SQL
Statement option and then enter the statement into the text box. You can
enter Select, Update, Insert, and Delete statements by selecting the
appropriate tab.
• To use stored procedures with a SQL data source, select the Stored
Procedure option and then select the stored procedure you want to use
from the drop-down list that's dis- played.
• When you use custom statements, Visual Studio doesn't generate Update,
Insert, and Delete statements from the Select statement you enter. Because
of that, you have to enter each of these statements yourself or use the
Query Builder to generate them.
DATALIST CONTROLS
the DataList control is a web server control used for displaying repeated
sets of data in a customizable layout. It allows you to define templates for
the display of each item in the list.
Here's a brief overview of the DataList control:
Templates
Data binding
Repeater Control
• The templates you define for a data list specify what content to display
and what controls to use to display it. At the least, you must create an Item
template that defines the items from the data source that you want to
display.
HOW TO FORMAT A DATA LIST
• You can format a data list by applying a predefined scheme, by using the
Properties dialog box, by using the Properties window, or by editing the
aspx code.
• To apply a scheme, choose Auto Format from the control's smart tag
menu and then select the scheme you want to apply.
• To use the Properties dialog box, choose Property Builder from the
control's smart tag menu and then set the properties for the data list and its
templates.
DATA BINDING
• You can bind any of the controls that inherit the ListControl class to a data
source. That includes the list box control, the drop-down list control, the
check box list control, the radio button list control, and the bulleted list
control.
• You can use the Data Source Configuration Wizard to select the data
source for a list control, the data field to display in the list, and the data
value to return for the selected item.
• You can also use the DataTextFormatString attribute of a list control to
specify a format string you want to apply to the text that’s displayed in the
control.