Teach you to do a simple VB database program __ Database

Source: Internet
Author: User
Tags ole

For beginners, do a database function VB program may not be simple, I am a beginner, forever beginner, I also deeply feel the difficulty of learning, in order to be able to find out a way to learn VB database, I found a lot of examples, consulted a lot of information, also tried a lot, Even a few days and nights did not sleep. Although the achievement is very small but I realized from the pain to the joyful process. The pain is long and long, and the transition to happiness is in a flash. Below I made a simple VB small program, I hope to help you.

(1) file-new-standard. exe

(2) Engineering-Parts Find and select: Microsoft ADO Data Control6.0 (OLE DB) and Microsoft DataGrid Control6.0 (OLE DB)

(3) Add the control as shown in the figure

"Name"--correspondence Text1, others are: Gender--combo1, Faculty--comobo2, advanced Mathematics--text2, sports--text3, computer--TEXT4

Add, delete, query, modify, save, exit

Add again: ADODC1 and DATAGRID1

For ADODC1, find in its property bar: ConnectionString uses the connection string. Connect to your database. (If you are not familiar with database asscess, I suggest you should first look at how others do a table with the name "score"), also in the following recordsource, select 2-adcmdtable, the process name selected "Score", is to link the score table to the ADODC control.

Added: Adodc1.Recordset.AddNew
Adodc1.recordset ("name") = Text1.Text
Adodc1.recordset ("gender") = Combo2.text
Adodc1.recordset ("faculties") = Combo1.text
Adodc1.recordset ("advanced mathematics") = Text2.text
Adodc1.recordset ("sport") = Text3.text
Adodc1.recordset ("computer") = Text4.text
Adodc1.Recordset.Update

Text1.Text = ""
Text2.text = ""
Text3.text = ""
Text4.text = ""
Combo1.text = ""
Combo2.text = ""

Delete: Adodc1.Recordset.Delete
Adodc1.Recordset.Update

Modified: Text1.Text = Adodc1.Recordset.Fields ("name")
Combo1.text = Adodc1.Recordset.Fields ("faculties")
Combo2.text = Adodc1.Recordset.Fields ("Gender")
Text2.text = Adodc1.Recordset.Fields ("Higher mathematics")
Text3.text = Adodc1.Recordset.Fields ("Sport")
Text4.text = Adodc1.Recordset.Fields ("Computer")

Save: Adodc1.recordset ("name") = Text1.Text
Adodc1.recordset ("gender") = Combo2.text
Adodc1.recordset ("faculties") = Combo1.text
Adodc1.recordset ("advanced mathematics") = Text2.text
Adodc1.recordset ("sport") = Text3.text
Adodc1.recordset ("computer") = Text4.text
Adodc1.Recordset.Update

Exit: Unload Form1
End

Query: My idea here is: Hide Form1, (ie form1.hide), show Form2. (ie form2.show)

Enter a name and click on the query to know his score.

Also add ADODC1. Same as above. Datagride is the same way.

Query: Adodc1.recordsource = "SELECT * from score WHERE name = '" + text1.text + "'"
Adodc1.Refresh:Set DataGrid1.DataSource = ADODC1
Datagrid1.visible = True

Added in Form_Load (): adodc1.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:/vb/db1.mdb; Persist Security Info=false "
Adodc1.recordsource = "SELECT * FROM Score"
Adodc1.Refresh:Set DataGrid1.DataSource = ADODC1

Oneself to understand understanding.

return: Form1.show
Form2.hide
Text1.Text = ""
Unload Form2


The above is my study in the process of a little bit of harvest, I hope to share with you, can provide a little help to our learners.

Finally, I hope you can achieve something, for our country's software business to contribute their strength.

2007.9.9 Night 21.50

                                                                                                             (Yuan Hua)   < original >

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.