Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Several problems about recordset objects in vb6 data control.
Several problems about recordset objects in vb6 data control.
Introduction demonstration of VB database' Note: VB visual database manager can't create ACCESS with password? Mdb database file or append password, but you can use MicrosoftAccess to manage the password of mdb database file or VB to append the password of mdb database. Rar attaches the password to the mdb database file. Note: Because of the visit? The password of mdb database file is weak, and there are many online accesses. Mdb database file password inquirer, so access? It doesn't matter whether the mdb database file has a password.

Note: "VB appended mdb database password. Rar "can only be used to append a password to an mdb database file without a password, and the password cannot be deleted or changed. "Note: This program uses data controls to connect to the MDB database. If the released program is an installation-free version, there must be three files of DAO350.DLL, MSJET35.DLL and VB5DB.DLL, and it needs to be registered as DAO350.DLL and MSJET35.DLL, otherwise the program cannot run normally. Options? ExplicitPrivate? Sub? Form_Load()

Load database

Database information check-error code jump code

Open? Mistakes? GoTo? Errmdbs:'''' Database connection with password.

'' data 1. Connect? =? "; PWD= 123456 "

'' data 1. Database name? =? App。 Path? & amp? "\mdb database. MDB。 Password 123456 "

''' What if? Directory (application. Path? & amp? "\ mdmddbase.mdb. Password 123456", vbReadOnly? Or? vbHidden? Or? vbSystem)? =? ""? then

'''''? MsgBox? "System error: The specified database file does not exist or is corrupted!" ,? 0? +? 16? +? 0,? "Program terminated"

'''''? end

'''' End? if

Passwordless database connection

Data 1. Connect? =? "Visit"

Data 1. Database name? =? App。 Path? & amp? " \ mddbase。 \MDB "

What if? Directory (application. Path? & amp? " \MDB mddbase.mdb ",vbReadOnly? Or? vbHidden? Or? vbSystem)? =? ""? then

MsgBox? "System error: The specified database file does not exist or is corrupted!" ,? 0? +? 16? +? 0,? "Program terminated"

end

End? if

Data 1. Record source? =? " MDBdate "? Database table entry

Data 1. Refresh activates the operation of the Data 1 control to make it effective for the operation of the database.

Data 1. "Recordset.Update" refreshes the data, which is necessary in some cases or methods, otherwise the data will not be saved in the database.

Data 1. Close' closes the database connected with the Data 1 control, and pay attention to whether it is necessary to use' Data 1' before use. Recordset.Update "to save data.

Data 1. Recordset.AbsolutePosition' obtains the serial number of the current data pointer "data1.recordset.movefirst" and selects the first row of data.

Data 1. ' Recordset.MoveLast?' Select the last row of data

Data 1. Record set. Move? N' Select the data in the nth row (note that the serial number of the first row =0) and exit? "Sub" detected a database-related error.

Errmdbs:

What if? Mistakes? =? "The password is invalid." ? then

MsgBox? "Critical: Database login password error, program terminated!" ,? 0? +? 16? +? 0,? "Error"

end

End? if

MsgBox? "System error: The specified database file does not exist or is corrupted!" ,? 0? +? 16? +? 0,? "Program Termination" ends.

End? Secondary private? Sub? Command2_Click()? Add data

Data 1. The function of' Recordset.AddNew' to add data is activated (it is added from the last line by default).

Data growth

Data 1. Recordset. Field (0)? =? "3" information, what is the data type? integer

Data 1. Recordset. Field (1)? =? Wang Wu? Name information, what is the data type? line

Data 1. Recordset. Field (2)? =? "789"? Password information, what is the data type? line

Data 1. Recordset. Field (3)? =? "

"'path information', what is the data type? line

Data 1. Recordset. Update refreshes the data. In some cases or methods, it is necessary to refresh the data, otherwise the data will not be saved in the database.

Data 1. Refresh activates the operation of the Data 1 control to make it effective for the operation of the database.

End? Secondary private? Sub? Command3_Click()? deleted data

Data 1. Recordset.MoveLast? Select the last row of data.

Data 1. Recordset.Delete' Delete data function is activated (the default is to delete the first row of data).

Data 1. Refresh activates the operation of the Data 1 control to make it effective for the operation of the database.

End? Secondary private? Sub? Command4_Click()? Search data

Data 1. Recordset.FindFirst? "Name? Like what? "Li Si"

Search result judgment

What if? Data 1. Recordset.NoMatch? =? Fake? then

MsgBox? "Have you found it? Name = Li Si? Data line of ","? 0? +? 64? +? 0,? "success"

other

MsgBox? "Didn't find it? Name = Li Si? Data line of ","? 0? +? 16? +? 0,? "failure"

End? if

MsgBox? Data 1. Recordset.AbsolutePosition' gets the end of the serial number of the current data pointer? Secondary private? Sub? Command5_Click()? update data

Data 1. Record set. Move? 1' Select the data in line 2? The sequence number of the first line is 0.

Data 1. Record set. Editor? Modify data function is activated (the default is to modify the data in the first line).

Write as new data

Data 1. Recordset. Field (0)? =? "3 1"

Data 1. Recordset. Field (1)? =? "New Wang Wu"

Data 1. Recordset. Field (2)? =? "New password 789"

Data 1. Recordset. Field (3)? =? "\ \ New 789\ New 789"

Data 1. Recordset. Update refreshes the data. In some cases or methods, it is necessary to refresh the data, otherwise the data will not be saved in the database.

Data 1. Refresh activates the operation of the Data 1 control to make it effective for the operation of the database.

End? Secondary private? Sub? Command6_Click()? Export data (default export except the first line of data)

Data 1. Record set. Move? 1' Select the data in line 2? The sequence number of the first line is 0.

Label 1。 Title? =? Data 1. Recordset. Field (0)

Label 2. Title? =? Data 1. Recordset. Field (1)

Label 3. Title? =? Data 1. Recordset. Fields (2)

Label 4. Title? =? Data 1. Recordset. Field (3)

End? Secondary private? Sub? Command7_Click()? Get headquarters data

Data 1. Recordset.MoveLast? Move the pointer to the last record in the table? This line is added mainly to reduce the wrong answers caused by the damage of the database itself. If the pointer cannot point to the last line, the system will report an error.

Label 6. Title? =? Data 1. Recordset.RecordCountEnd? Secondary private? Sub? Command8_Click()? Automatic numbering idea

Traverse the total number of rows in the database, and edit the values under each row of numbering items synchronously, so as to modify the numbering in batches.

Data 1. Recordset.MoveLast? Move the pointer to the last record in the table? This line is added mainly to reduce the wrong answers caused by the damage of the database itself. If the pointer cannot point to the last line, the system will report an error.

Dim? Me? As? long

For what? Me? =? 0? Where to? Data 1. Recordset.RecordCount? -? 1

Data1.recordset.movefirst' starts from the first line and the direction is downward. (This row must be added to the data control, otherwise the search direction will be confused. )

Data 1. Record set. Move? I

Data 1. Record set. Editor? Modify data function activation

Data 1. Recordset. Field (0)? =? Me? +? 1? Write information (self-increasing number)

Data 1. Recordset. Update refreshes the data. In some cases or methods, it is necessary to refresh the data, otherwise the data will not be saved in the database.

Data 1. Refresh activates the operation of the Data 1 control to make it effective for the operation of the database.

Quit for

then

End? Secondary private? Sub? Command 1_Click()

Data 1. Close the database connected by Data 1 control, and pay attention to "Data 1. Before using the data, you need to use "Recordset.Update" to save the data.

end

End? Sub?

Brief introduction of VB database:

1: VB creates a database file;

1- 1: Start VB Editor-Add-in (a)- Visual Data Manager (v)- File (f)- New (n)-Microsoft Access (m)-Version 7.0 MDB (7)

1-2: Create a window, enter a file name (such as MDB database)-Save.

Enter the database window.

1-3: Right-click Properties-Create New Table

Enter the table structure interface.

1-4: table name (n) (for example, MDBdate)-Add field (a)

1-5: Name-Type-Size-Fixed/Variable Field-Allow Zero Length-Required, and other parameters are determined according to the situation.

1-6: Loop 1-5 to create multiple forms-Close

Return to the table structure interface, and if there are no errors, generate table (b).

Back to the database interface

1-7: right-click MDBdate-Open (o)

Enter the database editing interface.

1-8: Add (a)- Edit corresponding information as appropriate-Update (u)

1-9: Loop 1-8 to add more information-Close (c)

Back to the database interface

1- 10: At this point, the database has been established and the visual data manager can be bifurcated.

2.VB connection database file:

2- 1: start VB editor-create a new project

2-2: Add Control Item (P)- Component (O)- Check "Microsoft FlexGrid Control 6.0"-Application (A)

2-3: Draw two controls Data 1 and MSFlexGrid 1 on the form.

2-4: basic properties of data1control

Data1.caption = "Name of data1

Data 1. DatabaseName = "Data 1 database location setting to be connected "or in code (such as app.path &; "\mdb database. MDB”)

Data1.recordsource = "data1table name of the connected database"? The name of the new table we created above is "MDBdate", so we use "MDBdate" here.

Data 1. RecordsetType = Data 1 Control has three values for the database operation mode: table = full control (instant data refresh) dynamic set = full control (refresh data after manual saving or code saving, default value (recommended value)) snapshot = read-only mode (data cannot be refreshed).

Data 1. Exclusive = False/true database * * * exclusive mode or exclusive mode (False is * * * exclusive mode, the default value).

Whether data1.readonly = false/true can modify the database file. (False is writable mode, the default value)

Data1.visible = true/false (data1whether the control is visible)

2-5: basic properties of msflexgrid1control

Msflexgrid1.datasource = "data source of msflexgrid1"? (Just set it to "Data 1", because we have connected the specified database with Data 1, and MSFlexGrid 1 is basically a data display control).

2-6: Done. Debugging code can browse database data on MSFlexGrid 1 control.

Note: If the VB development environment uses data controls to connect to the MDB database, if the released program is an installation-free version, it must have three files: DAO350.DLL, MSJET35.DLL and VB5DB.DLL, and it needs to be registered as DAO350.DLL and MSJET35.DLL, otherwise the program cannot run normally.

Note: VB visual database manager can't create ACCESS mdb database file with password or additional password, but you can use MicrosoftAccess to manage the password of mdb database file or use VB to add mdb database password. Rar "attaches the password to the mdb database file.

Note: Because the password of the ACCESS mdb database file is very weak, and there are many password searchers on the Internet, it doesn't matter whether the ACCESS mdb database file has a password.

Note: "VB appended mdb database password. Rar "can only be used to append passwords to mdb database files without passwords, and cannot be deleted or changed.

*****************************************************

If you see this, you have almost mastered the basic operation of data+mdb, and you only need a reasonable code combination to complete it. For example, the functions such as deletion and modification in the previous example are all aimed at the specified line. If you match the search function, you can delete or modify the specified row. I didn't test the date question you asked. I guess it's a question of statement conversion. Secondly, you can try the method of judging the split date and combining it back. In addition, I have an example of personal disk manager made by data+mdb for Internet cafe users. You can ask me for it if you need it. Finally, I wish you success!