VB & database interaction-knowledge point sorting in classic 5 instances

Source: Internet
Author: User

1. on error Statement (start an error handler and specify the position of the subroutine in a process; it can also be used to disable an error handler .)

If you do not use the on error statement, any running errors are fatal. That is to say, the result will display an error message and stop running.

Note: An error handler is not a sub or function process. It is a piece of code marked with line labels or line numbers.

Syntax

On Error goto line

On Error resume next

On Error goto 0

The on error statement syntax can take any of the following forms:

Statement description

On Error goto line starts the error handler, and the routine starts from the line specified in the necessary line parameter. The line parameter can be any line label or line number. If a running error occurs, the control jumps to line to activate the error handler. The specified line must be in the same process as the on error statement; otherwise, a compilation time error occurs.

On Error resume next indicates that when a running error occurs, the control forwards it to the statement after the wrong statement occurs, and continues running here. This method is used to access objects without using on error Goto.

On Error goto 0: Disable any started error handling programs in the current process.

In instance 1, on Error goto refers to the jump when the program runs an error (and can find out the type and number of the error so that people can easily analyze it or make our program more structured error into a special error handler)

Source Document

2. cursor attributes

1. adopenforwardonly (default) can only move one row forward at a time.

2. adopenkeyset open the keyset type cursor.

3. Open dynamic type cursor in adopendynamic

4. Open static type cursor in adopenstatic mode.

Specifically: adopenforwardonly and adopenstatic make the record set read-only, which indicates creating a snapshot of data. The latter is more flexible than the former because it can be moved in any direction.

The adopenkeyset can be moved freely and can be changed. When other users add or delete Record Sets, this cursor cannot be reflected. However, it reflects the changes made by other users to the record set.

Adopendynamic allows all operations. Other users add, delete, and modify Record Sets in this record set

Are visible.

Adlockreadonly (default) read-only --- data cannot be changed.

Adlockpessimistic pessimistic lock (one by one)-to ensure successful completion of the work required to edit records,

Lock the records of the data source immediately during editing.

Adlockoptimistic optimistic locks (one by one)-the record is locked only when the update method is called.

Adlockbatchoptimistic optimistic batch Update-used in batch update mode (relative to the immediate update mode ).

Source Document

3. Difference Between definedsize and actualsize

The definedsize attribute returns a long value, which indicates the defined length (in bytes) of a field ).

The actualsize attribute is a read-only attribute. It returns a long value indicating the actual length of a field value. If ADO cannot determine the length of the field object value, adunknown is returned.

Use the definedsize attribute to determine the data capacity of the Field object, while actualsize indicates its actual length.

Source Document

4. What are fields, records, and values?

In a database, the rows and columns of a table have special names. Each column is called a "field ". Each field contains information about a topic. Just like in the "Address Book" database, "name" and "contact number" are the attributes common to all rows in the table, therefore, these columns are called the "name" field and the "contact number" field.

Each row in the table is called a "record". Each record contains all the information in this row, just like all the information of a person in the address book database, however, there is no special record name in the database, and the number of records is usually indicated by the number of rows it contains.

The data stored in the database at the intersection of rows and columns in the table is called "value". It is the most basic storage unit in the database. Its location must be defined by the records and fields in the table. In the address book table, we can see that the value at the intersection of the first record and the unit field is "People's Bank of China Shanghai Branch ". The "value" on the Cross-location of the "Wang Lan" record and the "phone" field is "0551-7238321 ".

Source Document

Example:

5. "objdatasource! Username = objrs! Username "???

In Visual Basic, the exclamation point "!" And Dot "." are used to name the object, but there is a big difference in the syntax between the two, which requires special attention during programming.

The dot operator "." is used to represent the attributes and methods of an object. The object name, dot, and required attributes or methods are used for reference. For example, you can use reponse $ = text1.text to reference the text attribute in the text box textl. If you want to change the unit returned by the form1 form or read the object height, it is represented by form1.scaleheigh = 2000.

Exclamation point "!" It is often used when a control is accessed as a feature. For example, when you reference the text attribute of the text1 text box in fomr2, you can use response $ = form2! Text1.text syntax format.

Although the syntax application structure of the two statements is quite different, the performance of the two statements is the same. It is worth noting that if you are in the exclamation point "!" You can use "." to obtain direct access to the text1 feature on the form.

To further increase your perceptual knowledge, run the following example:

1. Create a new project and add a command control to the form1 form.

2. Double-click the form1 form, edit the form-load event, and enter:

Form1! Command1.caption = "text"

Form1.command1. Caption = "It Works"

3. Run the trial project. Then you will see the string it works in the command1 command box.

To clearly define the referenced control name and the properties or methods of the control in the program and increase the readability of the program, it is best to use the exclamation point "!", This is also recommended for VB.

Source Document

6. 0, "" (empty string), null, empty, and
Nothing differences

Answer the following questions first! After the following descriptions, which of the following variables is equal to 0, "", null, empty, and nothing?

Dim

Dim B as string

Dim C as integer

Dim D as object

A is equal to empty, because uninitialized "unfinalized variables" are equal to empty. However, if a = "" or a = 0 is detected, the true value can also be obtained.

B is equal to "", because uninitialized non-fixed-length "strings" are equal "". Note that B <> null.

C is equal to 0. Is there any problem?

D equals to nothing. If no object is set, "object variable" is equal to "nothing", but do not use d = nothing. Instead, use D is nothing to determine whether D is equal to "nothing, because the equal sign is not =.

The most confusing part is the reserved word null. Please refer to the following statement:

Print x = NULL

Print x <> null

All results are output null (Neither true nor false). This is because if any formula contains null, the formula is equal to null, in fact, to determine whether a certain data is null is definitely not usable:

If X = NULL then \ 'will always get null

Use:

If isnull (x) then

Which data type is equal to null? Except for the null formula, the "data field" (in the database) that does not input any data is equal to null.

Source Document

7. Use object programming

Object usage:

<1> declaration of (reference) object dim object name as new [database name.] Class Name (this is the name of the loaded object, which is created only when used for the first time)

<2> dim object variable name = [database name.] Class Name

Set object variable name = new [database name.] Class Name (actually created)

New: Creates a new instance. instance reference is assigned to the object name, that is, the new instance name is the object name.

Example: dim myform2 as form1

It indicates that the type of myform2 is form1. At this time, myform2 still does not have an object corresponding to it. When the set myform2 = new form1 statement is added, it is the same as dim myform2 as new form1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.