database programming of visual basic
visual basic conduct and actions applied the " sharp weapon" of development of the procedure also expresses on the database development of applying the procedure, it good interface with mighty control a function makes database plait the distance mulched become simple. but even if such, the database applies the development of the procedure to still calculate top is knowledge( certainly this is very simple of) that vb plait distance inside of a little bit difficult, this is because you not only want to acquaint with the vb inside to weave the distance concerning the database still understand the knowledge of the database. so we introduce first the basic knowledge of the database, be regarded as the warm-up exercise that study database weave distance front!
one, warm-up exercise
needing first avowal is, relation database that database knowledge that we here introduce all point. the so-called relation database is to means data as that the form gather, passing to establish simple form an a kind of database for of relation to defining construction.
i ignore the watch at how saving way in physics in the document in database is, it can see to make an a line for with row, with electronics form is similar with the row. in relation database, the line were called the record, but the row then is called word segment. the underneath is an example of customer's form.
table 1 customer form
customer's number name address city street postal code
1723 doe john 1234 fifth avenue new york ny 1004
3391 smith mary 9876 myrtle levee boston ma 6078
3765 blasé mortimer 2296j river road peoria il 7011
this form inside each an all in formations for is a record, it including particular customer, but each record then included the same type with the word segment of the quantity: customer's number, name etc.
form is logic set that a kind of related information that press a line of arranging with row, similar in single form in work.
each row of the word a database form inside calls a word segment. watch is from every kind of word a definition of its containment of, each word a data for describing its implying. while creating to set up a database, the beard assign for each word segment a the piece belongs to the sex with the other according to the type, biggest length. the word segment can include every kind of word sign, arithmetic figure even sketch.
an information of relevant customer deposits in the line of the form, is called record. by any large, arbitrarily two records for database form to create set up can't be same.
key be a certain word segment( or several words segment) of the form inside, it() for fast inspect but drive index. the key can be unique, and also can then the right and wrong is unique, being decided by it() whether admission repetition. unique key can specify for main key, using each one that come to unique marking form. for example, in anterior example, customer the marking number( customer's number) is the main key of the form, because customer's number was uniquely the marking a customer.
the relation database can be constituted by several forms, form and form can in different way mutually connection. for example, customer's database can also have the form of all order forms of a certain customer in a containment. it only use a customer that an each repetition all customer's information for quoting from that order form, but not in order form, is shown as watch below:
table 2 order the form
order customer's number date contents quantity
14764 3391 2/23/94 27 $22.95
14932 3391 3/17/94 46 $9.57
15108 8765 2/15/96 27 $22.95
in this form, customer the number word segment quoted from the customer's customer in the form number word segment, from but contact the order form with the customer. can see, customer 3391( mary smith) ordered on in february of 94 23 27 item, ordered on in march of 94 17 46 item. use to be called the exterior key to the key that establish the relation, because of it with the main key connection of the " exterior" form( customer's form).
a rightness of many relate to last relation in the form type more to be called a rightness of much relating to with many rightness, a certain and particular order form can be a customer a hair because a customer can send out several order forms, .can also establish many a relation for munchies. for example, the inventory form of the item( stock) that list the all selling:
table 3 inventory form
contents describe supplier expenses inventory
27 straw hat garden supply co. $14.00 50
46 garden gloves garden supply co. $4.50 75
102 hanging floral industries $6.00 137
from the inventory form inside, can see to exists with the stock an at the customer many a relation for mulches. too is to say, a customer can order several stocks item, but a stock item is again can drive several customers order. many right nesses much relates to is to pass two independence a rightness of to much relate to define of, the public" many" form included the exterior key of two other forms. in that example, order goods the s form to is all and mutually with the form of customer( pass customer's number) with inventory form( pass the " contents") the connection. pass these three forms, we can see, the mary smith( customer's number 3391) ordered the straw hat(" contents"27) with the garden gloves(" contents"46), but the mary smith( customer's number 3391) ordered the straw hat with mortimer blaselflatz ( customer's number 8765) all.(" contents"27)if orders goods customer's form with the related word segment of the inventory form and form of" order goods" the word a coupling gets up, establishing a" connection" form, so this relation clearer.
table 4 connection form
order customer's number name contents describe
14764 33391 smith mary 27 straw hat
14932 33391 smith mary 46 garden gloves
15168 8765 blaselfatz mortimer 27 straw hat
the norm turns the database design of mission be method that the data of buildup, but the data of buildup, should can dissolve otiose repetition, and for have the necessary information offering to check to seek the path quickly. for attaining this kind of target but separate information to the process gone to in every kind of independent form, be called the norm turn.
it is complicated process to use many appointed rules to proceed the norm with the type of the different class that norm turn. that process studies and discuss already beyond the reach of textual scope. but, the norm of the simple database in majority turn and can use the simple experience in underneath rule completes: include the form of the information of repetition must be divided into independent a few forms dissolve repetition.
for example, make student with course to should of student's database, included the next the information that watch show.
table 5
student course describe professor
1 4 introduction to physiology dawson
2 3 applied basketweaing carruth
3 1 physics for short-cooks adams
4 2 introduction to physiology damsons
if have chosen to learn 12 curricular 1000 students, the each curricular elucidation will show with the teacher 100 many- to choose that curricular and each student repeat once. to avoid this kind of low efficiency, should to turn the dichotomous and independent form in form to the norm, an is used to mean the student, the another uses mean the course, such as table 6, table 7 show.
table 6
student course
1 4
2 3
3 1
4 4
table 7
course describe professor
1 physics for short- cooks adams
2 counterculture sociology beckley
3 applied basketweaing carruth
4 introduction to physiology damsons
now the form was turned by the norm, so, to changes the particular and curricular course describe or" data", as long as change a record all right.
is a basic knowledge concerning database above, this is what study database plait distance must. although the database technique is used as a course, its depth is not this space and can describe with the wide degree of, be used as the primer with simple database plait the distance should be all right already.
like, underneath we can start practicing. we usually meet the database system is to registers the system, ignoring you are in the unit, or attend what buildup, the register is to cans not help of, and it of the construction is more simple, we take a register system as an example. the analysis is once a data for involving.
two, understanding the elements
for the register, want the on the trail of information include:
● name ● sex
● native place ● age
● date of birth ● unit
● address ● postal service codes
● telephone ● fax
certainly, can create to set up a form in brief, make above each piece according to item to should a word segment.
need to point the form the main key in parties now, in order to unique marking each a record, increase register number conduct and actions unique key respectively in register form, guarantee a two records like this all different.
to the database after making an above analysis, we can start establishing the database.
three, set up the firm in camp
here we study to establish the database how, needing to make sure the type that to establish the database first. pass in visual basic the data interview control piece or data interview object ( dao) can visit the following database:
1. the database of jet, namely microsoft access
2. the database of isam, such as: dbase, etc. of foxpro
3. the database of odbc, every follow the standard of odbc customer/ server database. such as: microsoft sql server, oracle
by any large, if develop the personal small scaled database system, use access database comparison accommodation, to develop the big and medium-sized database system uses the database of odbc fester. but dbase with the database of foxpro because of already dated, unless special circumstance, do not use otherwise. in our example, chose to use the database of access certainly. establish the database of access contain two kinds of methods: while establishing the database in microsoft access. click" new set up" button can establish the new form.( such as figure 1)here we main introduction the second method: the usage can see to turn the data management machine, do not need to weave the distance and then can create to set up the database. can see to turn the data management machine is the applied procedure of a great use, it is a vb business enterprise version is supplementary with the profession version, in the catalogue\..\ devastation\ vb\ samples\ the visdata is next, its interface is as follows the diagram.
click the menu" document" item is next" new set up" son item" microsoft access" son item of" edition 7.0 mdb" item. input the new setting up the name of the database in flick window way open" register", appear the underneath figure 3 show the window way:
want the born and new form, the single shot in right key database window way flicks the menu open, then the choice" new form" ordinaries, establishing in" watch construction" dialog box appeared later on a word for wanting segment. the every time faces to join in the form new word segment, single shot" increment word segment" button, will appear the figure 4 of" increment word segment" dialog box.
"increment word a type for" options in the dialog box, such as table,10 showing, according to word segment. in our the register database that establish, the type of the each word segment, such as table11.
want to notice of is, because the word segment registers the number be used unique marking record of, therefore, it can't be inputted by customer. so while defining the word's segment need to be defined for long data type, the " automatic born word segment" item is valid, and picks out this item. be the customer like this to input to record with other the different value every input a new record, system would on the word's segment automatically.
in access database, the key word realizes with the index of, conduct and actions plait distance personnel at gather to weave the distance to the record of the form type, needs to adjust to use index. while searching, the technique of rushmore uses the index information the excellent turning the search automatically. after completing the form definition, click" increment index" button, flick such aspen figure 5 show the window way.
in window way the right side contain three optioned, its meaning, such as table,12.
increase the index dialog box options
after completing such as figure 6.
certainly, the academic association database establishes too not a dynasty the business of the one night, the reader no harm much practices once. underneath you can circulate the vb started our plait distance.
four, a long distance meets
applied procedure in the database of visual basic contain three parts, such as figure 7 show.
customer procedure is part that procedure member development of, and also is we will soon weave to write with the vb. the database engine is a database to drive the procedure, using its procedure member can use united format interview every kind of database, whether this database is a native the database of visual basic, or an other the database format of any format for supporting, a data for using interview object is similar to wove distance technique is all. the database is then the part that we up complete. can see from this construction the customer have nothing to do with at the particular database that visit. that we at use the vb the plait write the database procedure, need to can make the procedure visit the appointed database.
if is a simple database applied, can use the data control piece to carry out big and parts of data interview operate, but basic need not plait writes the code. control an a data for or several words segment for controlling mutually and bindingly first piece the automatic manifestation comes from the front record with the data. |