Use VB.NET and Acess to combine simple phone number this program (2)

zhaozj2021-02-11  189

All source code is downloaded here:

http://www.up2e.com/resource.php

Use VB.NET and Acess to combine simple phone number this program (2) --by zigz (Luhai) Luluhai@eastday.com

IV) When relevant knowledge gets the course design topic, understand this question and database related, and .NET introduces new ADO.NET data access technology, so we will learn about this knowledge, see how she is Access combines the establishment of a database program, discovering in the learning process to use the SQL statement to implement an increase in the database, query, modification, and deletion. The OLEDBConnection control is used to connect to the database, and the OLEDBCOMMAND control is used to send a SQL command to the database to complete the operation of the database.

Several knowledge points are as follows: 1) SQL language A, SELECT statement Its primary use is to get a data set from the data table, his syntax is as follows: Select SelectList from Tablename [Where searchCondition] b, the INSERT statement is used to bring to the database table Insert a new record, his syntax is as follows: INSERT [INTO] TABLENAME [(Column List)] VALUES (Default | Null | Expression) C, DELETE statement is used to delete records in the database, his syntax is as follows: Delete from Tablename [Where SearchCondition]

2) ADO.NET data object where the OLEDBConnection control is used to connect with the database, and the OLEDBCommand control is used to send a SQL command to the database to complete the operation of the database.

5) Programming Thinking and Key Projective Thoughts is to establish a connection to the Acess2000 database by setting an OLEDBConnection control, adding a record, deleting a record, using the OLEDBDataReader to display all records of the database through the OLEDBDataReader. Combine the ListView control.

1) The implementation of the addition button function first writes a function addRecord () for adding a record.

Private sub addrecord ()

Label5.visible = false

ErrorProvider1.seterror (homephone, "")

ErrorProvider1.seterror (Mobilephone, "")

OLEDBCONNECTION1.Open () 'opens the connection

OLEDBCOMMAND1.COMMANDTEXT = "INSERT INTO TXL (Name, Mobilephone, Homephone, Email) VALUES ('" tbname.text ",'" mobilephone.text ", '" homephone.text ",' " email.text " ")"

OLEDBCOMMAND1.EXECUTENONQUERY () 'Add a line to the database

TBNAME.TEXT = "" 'Clearing all

MobilePhone.Text = "" P

Homephone.text = ""

Email.text = ""

Messagebox.show ("has successfully added a record!", "Info", messageboxbuttons.ok) oledbconnection1.close () Close connection

End Sub

Then click the "Add" button Click the event function:

Private sub btadd_click (Byval E AS System.EventArgs) Handles Btadd.click

If tbname.text = "" "" If the user does not enter your name

Messagebox.show ("Sorry! Please enter your name.", "Info", messageboxbuttons.ok, messageboxicon.warning)

Elseif Not MobilePhone.text = "" THEN

IF not isnumeric (Mobilephone.text) THEN

ERRORPROVIDER1.SETERRROR (Mobilephone, "1")

Label5.visible = true

Else

AddRecord ()

END IF

Elseif Not HomePhone.text = "" THEN

IF not isnumeric (homephone.text) THEN

ErrorProvider1.seEterror (Homephone, "1")

Label5.visible = true

Else

AddRecord ()

END IF

Else

AddRecord ()

END IF

End Sub

2) Implementation of Removing Recording Function Figure 7 Delete Record

The program is also mainly to establish a connection with the Acess2000 database by setting an OLEDBConnection control, and the ability to delete records is implemented by setting the COMMANDText property between OLEDBCommand.

Private sub button1_click (byvale as system.object, byval e as system.eventargs) Handles Button1.click

If tbdel.text = "" "" "

Messagebox.show ("You haven't entered your name yet!", "Info", messageboxbuttons.ok)

Else

DIM Mainform as new form1 ()

Mainform.oledbcommand1.commandtext = "delete from txl where name = '" TBDEL.TEXT "'"

Mainform.oledbconnection1.open ()

Mainform.oledbcommand1.executenonQuery ()

Messagebox.show ("I have deleted success!", "Info", MessageBoxButtons.ok)

Me.close ()

END IF

End Sub 3) About the list of code displayed Private Sub showall_load (Byval e as system.EventArgs) Handles mybase.load

DIM Mainform as new form1 ()

Dim Reader as Oledb.oledBDataReader

Mainform.oledbcommand1.commandtext = "Select * from txl" mainform.oledbconnection1.open ()

Reader = mainform.oledbcommand1.executeReader 'Returns all records

Do While Reader.Read 'lists all records with listview

DIM Li as new listviewItem ()

li.subitems.clear ()

li.subitems (0) .Text = Reader ("name"). Tostring

li.subitems.add (Reader ("Mobilephone"). TOSTRING)

li.subitems.add (Reader ("Homephone"). Tostring)

li.subitems.add (Reader ("email"). TOSTRING)

ListView1.Items.Add (li)

Loop

Reader.close ()

Mainform.oledbconnection1.close () 'Close connection

End Sub

At this point, the key code is so much, please see my original file in detail. to sum up:

My program looks small, but I actually function a lot, although I didn't make the function of the query record, but that is, it is exactly the same, the mode of deleting records is exactly the same, it is necessary to replace different SQL statements. Full text. By Zigz (Luhai) Luluhai@eastday.com

转载请注明原文地址:https://www.9cbs.com/read-3748.html

New Post(0)