Académique Documents
Professionnel Documents
Culture Documents
BSc-II (Computer Science) the Color Set is set to Windows System Colors.
Font
Visual Basic and Database Notes
VB Controls Properties Font properties that may be changes.
Frames are used to provide a border within the form that includes a caption.
Frames are used to organize forms. Font Choose a font installed on this system. It's wise to choose
standard Windows fonts such as MS Sans Serif that are
universally available.
Frames are also used to organize option buttons into related groups. In
compiled Visual Basic, frames will automatically group option buttons if the
option buttons and frames are created in the correct sequence. In Manifold, Size Size of font, in points.
frames are simply visual artifacts used to organize the form. We can use the
group property of option buttons (see below) to organize them in a standard Effects Bold, Italic, Underline or Strikeout.
VB way.
Sample Text A preview of the selected settings.
To Add an Frame to a Form
File System Controls
1. Click on the Insert Frame button in the Tools toolbar. (DriveListBox, DirListBox, FileListBox)
2. Click and drag the location and size where it is to be created in the
form.
VB provides three native toolbox controls for working with the
3. Continue to create any additional frames desired.
file system: the DriveListBox, DirListBox, and FileListBox. You
4. Right click onto each button and choose Properties from the
context menu.
can use these controls independently, or in concert with one
5. Set the properties for the frame as desired. Note that each frame
another to navigate the file system.
must belong to a group. The DriveListBox control is a specialized drop-down list that
6. Move, resize and align the frame as desired. displays a list of all the valid drives on the user's system. The
Properties most important property of the DriveListBox is
the Drive property, which is set when the user selects an entry
In addition to the properties listed below, a Control tab provides access to
certain frequently used form properties for this control. See the Form
from the drop-down list or when you assign a drive string
Properties topic for information on those properties. (such as "C:") to the Drive property in code. You can also read
the Drive property to see which drive has been selected.
Frame To make a DirListBox display the directories of the currently
General
selected drive, you would set the Path property of the
DirListBox control to the Drive property of the DriveListBox
Caption Text used to label the frame. Font is set in the font tab. control in the Change event of the DriveListBox, as in the
following statement:
MousePointer The type of mouse pointer displayed when over the frame.
Choose from 16 different types plus a custom pointer
Dir1.Path = Drive1.Drive
The DirListBox control displays a hierarchical list of the user's
Appearance 3D or Flat. 3D is the standard Windows look. Flat results in a disk directories and subdirectories and automatically reacts to
rectangular square of background color with a foreground color
border and caption. mouse clicks to allow the user to navigate among them. To
synchronize the path selected in the DirListBox with a
BorderStyle FixedSingle (default) or None. None may be used with FileListBox, assign the Path property of the DirListBox to
Flat Appearance to achieve an uncaptioned rectangle of
background color. the Path property of the FileListBox in the Change event of the
DirListBox, as in the following statement:
OLEDropMode Set to None (default) if the frame does not accept OLE drops and File1.Path = Dir1.Path
is to display the No Drop cursor if an OLE drop is attempted. Set
to Manual, the frame will trigger OLE drop events, allowing The FileListBox control lists files in the directory specified by its
programs to handle the OLE drop operation in code. Path property. You can display all the files in the current
Enabled True or False. True means the object can respond to user-
directory, or you can use the Pattern property to show only
generated events, false prevents it from responding. We can certain types of files.
disable a control like a text box if we wish it to simply display Similar to the standard ListBox and ComboBox controls, you
information in a read-only way.
can reference the List, ListCount, and ListIndex properties to
Color access items in a DriveListBox, DirListBox, or FileListBox
control. In addition, the FileListBox has a MultiSelect property
Back Color Color to be used for the frame's background, normally seen only
when Flat Style is used. which may be set to allow multiple file selection.
Fore Color Color to be used for the frame's foreground, the color of the text Unit# 6 Database Programming
caption.
Visual Data Manager
Color Set Choose from Standard Colors (standard Windows non-dithered The Visual Data Manager is a Visual Basic tool for
colors) or Windows System Colors. The latter will be defined by designing databases. Although it’s rather crude, you can
the user's Control Panel settings and is normally the setting used
so that the form changes appearance like the rest of Windows if use the Visual Data Manager to create and modify
the Control Panel settings are changed. tables, to implement security, and to experiment with
SQL. When you open an existing database, the Visual
Color Palette Displays available colors. Click on the property to be changed to
highlight it in the Properties pane, click on the desired color in Data Manager displays a database window listing the
the Color Palettepane and then press Apply. tables and properties of that database.
Entering data into DB: ADO Data Control:
In addition, You can use the Visual Data Manager The ADO (ActiveX Data Object) data control is the primary
for data entry. Double-clicking the name of a table in the interface between a Visual Basic application and a database. It
Database window opens-the table in data entry, mode, can be used without writing any code at all! Or, it can be a
and you can edit, add, and delete records. central part of a complex database management system. This
The Data Control: icon may not appear in your Visual Basic toolbox. If it doesn’t,
The data control is available on the standard toolbar. select Project from the main menu, then click Components.
After placing a data control on your form, you can edit its The Components window will appear. Select Microsoft ADO
properties, just like any other control. You can also set them Data Control, then click OK. The control will be added to your
from code at run time. toolbox.
The important properties of the data control, from the point of The data control can be used to perform the following tasks:
view of data access, are: 1. Connect to a database.
Connect - (not used when accessing Access 2. Open a specified database table.
databases) 3. Create a virtual table based on a database query.
DatabaseName 4. Pass database fields to other Visual Basic tools, for
Exclusive display or editing. Such tools are bound tools
Options (controls), or data aware.
ReadOnly 5. Add new records or update a database.
RecordSource 6. Trap any errors that may occur while accessing data.
DatabaseName: 7. Close the database.
Determines the path and filename of the database file (.MDB ADO Objects:
file for Microsoft Access). ActiveX Data Objects (ADO) is an application program
Exclusive: interface from Microsoft that lets a programmer writing
If this property is set to True, then when you open the Windows applications get access to a relational or non-
database you will have exclusive access to it. If set to False (the relational database from both Microsoft and other database
default) other users (or programs) can access the database providers. For example, if you wanted to write a program that
while you are working on it. If you are working on a single user would provide users of your Web site with data from an
database, set this property to true - it will improve IBM DB2database or an Oracle database, you could include
performance. ADO program statements in an HTMLfile that you then
Options: identified as an Active Server Page. Then, when a user
Determines access constraints for the tables you are working requested the page from the Web site, the page sent back
on. would include appropriate data from a database, obtained
ReadOnly: using ADO code.
When True, you cannot update the database (default is False). OLE DB is the underlying system service that a
RecordSource: programmer using ADO is actually using. A feature of ADO,
Determines the source of the set of records (the RecordSet) Remote Data Service, supports "data-aware" ActiveX controls
retrieved by the data control. This property will be set either in Web pages and efficient client-side caches. As part
to the name of one of the tables in the database, to the text of of ActiveX, ADO is also part of Microsoft's overall Component
a valid SQL query, or to the name of a predefined query in the Object Model (COM), its component-oriented framework for
Access database. putting programs together.
Viewing the data with the Bound Controls: ADO evolved from an earlier Microsoft data interface, Remote
The easiest way of viewing the data is by using one or more of Data Objects (RDO). RDO works with Microsoft's ODBC to
the following 'bound controls' (available in the learning access relational databases, but not non-relational databases
edition). such as IBM's ISAM and VSAM.
Check box - Use for True/False data Data Environment
Image - Use for image data Data Environment object is created and managed using Data
Label - Use for "non user-editable" data Environment designer. A Data Environment object can
Picture box - Use for bitmaps accomplish any of the following tasks.
Text box - Use for "user-editable" data
• Can contain connection and command objects
Data AccessObjects (DAO): • Can establish relationship between command object to
DAO (Data Access Objects) is an application program interface represent hierarchies
(API) available with Microsoft's Visual Basic that lets a • Can group data and get aggregates
programmer request access to a Microsoft Access database. • Allows fields to be dragged and dropped on to a Data Report,
DAO was Microsoft's first object-oriented interface with for report, and a Form for data entry screen
databases. DAO objects encapsulate Access's Jet functions. • Can work as source for Databound control such as
Through Jet functions, it can also access other Structured DataCombo controls and Hierarchical Flexgrid control.
Query Language (SQL) databases. ADO and OLE DB offer a In order to work with Data Environment object, you have to
faster interface that is also easier to program. add Data Environment Designer to your project. Data
Environment Designer allows programmer to accomplish any
of the tasks mentioned above. Data Environment Designer is
invoked when you double click on Data Environment object in Database Management System
Project Explorer.
Chapter: Advanced SQL statements and Procedures
To add Data Environment object to the project: Topic: Defining your own messages in SQL
Select Project-> Add Data Environment. If Add Data
Environment option is not found then select More ActiveX sp_addmessage
Designers and then select Data Environment. Stores a new user-defined error message in an instance of
Introducing the DataGrid: the SQL Server Database Engine. Messages stored by
The DataGrid control combines a data display using sp_addmessage can be viewed by using
function (such as the VB Label control) and a data the sys.messages catalog view.
navigation function (such as the VB Adodc control) into a
single control. DataGrid sports a highly functional Syntax:
spreadsheet-style user interface. It has many special sp_addmessage msg_id , severity , 'msg'
features for formatting, displaying, updating, and [ , 'language' ]
manipulating the data displayed in its rows and columns. [ , [ @with_log= ] { 'TRUE' | 'FALSE' } ]
As an example for this article, I have used DataGrid and [ , 'replace' ]
an extremely small amount of code to access an AS/400
file named ORDERS (the file, contained in a *SAVF object, The actual error message is "msg", which uses a data type of
and example code can be downloaded from the MC Web nvarchar(255). The maximum characters limit is 2,047. Any
site at www.midrangecomputing.com/mc). You can use more than that will be truncated. The language is used if you
ADO objects to open the database connection and file want to specify any language. Replace is used when the same
and to connect those objects to the DataGrid, which will message number already exists, but you want to replace the
string for that ID, you have to use this parameter.
navigate and display the contents of the file.
Data Report Designer:
The Data Report Designer supports hierarchical data Arguments:
commands that return a recordset containing a child
recordset, which is related to the parent by a key. You
“msg_id” is the ID of the message. msg_id is int with a
can create reports from these recordsets and perform
default of NULL. msg_id for user-defined error messages
grouping operations. Hierarchical data commands are
can be an integer between 50,001 and 2,147,483,647.
based on the hierarchical cursor feature in ADO 2.0 and
the Data Environment Designer.
The combination of msg_id and language must be unique;
You create the report using graphical object called Data
an error is returned if the ID already exists for the
report designer controls. Data report designer controls.
specified language.
Include: a data-bound Textbox control, a function control
which displays calculated figures, and Image control for
“Severity” is the severity level of the error. severity is an
inserting graphics, labels that display captions, and a line
int with a default of NULL. Valid levels are from 1 through
and a shape control that graphically organizes the data.
25.
Note: See example from internet.
'msg' is the text of the error message.
DENY
DENY blocks access. If a user has both a GRANT and a DENY on
a given object, by whatever means, the DENY will take effect.
For instance, let's consider the case of a GRANT SELECT against
the Test schema. This would give the ability to issue a SELECT
against any table or view in the Test schema. Try just applying
this permission, re-checking the permission, and then testing WHEN DOB < = ‘30’
the user's access to both Test.TestTable and Test.TestTable2. THEN ‘Young’
You'll see the user can now issue a SELECT query against both ELSE ‘Old’ FROM
tables. STUDENT
Query example:
SELECT ID, Name, DOB, CAST( nvarchar, DOB ) FROM
STUDENT
Output:
The output will be same as of CAST( ).
THE SYSMESSAGES
The sysmessages are used to generate system messages and
executed automatically when a specific event is occurred in
order to warn or notify the user. “Raiserror” is a sysmessage
which is used to notify about the error. Similarly throw is an
also error handler in sysmessges.