Verursachen von VB database applications mit ADO-control |
|
|
Jedoch ist Speicherverwaltung nicht ein sehr flexibles Werkzeug, weil sie nur mit begrenzten Arten von Daten arbeiten könnte und im grundlegenden sichtlichklima ausschließlich arbeiten muß. Wir können eine viel leistungsfähigere Speicherverwaltung in VB verwenden, das als ADO-control bekannt ist, um diese Beschränkungen zu überwinden. ADO steht für ActiveX Datengegenstände und während ADO ActiveX-gegründet wird, könnte es in den unterschiedlichen Plattformen (unterschiedliche Computersysteme) und in den unterschiedlichen Programmiersprachen arbeiten. Außerdem könnte es viele unterschiedliche Arten Daten wie Daten zugänglich machen, die in den Internet-Datenbanksuchroutinen, im email Text und in den sogar Graphiken anders als übliche Verwandtschafts- und nicht relationale Datenbasisinformationen geanzeigt wurden.
Verwenden ADO-Speicherverwaltung, mußt du sie in den Toolbox einsetzen und dies zu tun, Ctrl+T einfach betätigen, um das BestandteilDialogfeld zu öffnen und Microsoft ActiveX Speicherverwaltung 6 vorzuwählen. Nach nur diesem, du kannst fortfahren, deine ADO-gegründeten VB database applications zu errichten.
Das folgende Beispiel veranschaulicht, wie man eine verhältnismäßig leistungsfähige Datenbankanwendung mit ADO-Speicherverwaltung und zuerst von allen errichtet, die neue Form als frmBookTitle nennt und seinen Untertitel zur Buch-Fliesen ADO Anwendung ändert. Zweitens die ADO-Speicherverwaltung einsetzen und sie als adoBooks nennen und seinen Untertitel zum Buch ändern und folgend, die notwendigen Aufkleber, die Textkästen und die Befehl Tasten einsetzen. Die Laufzeitschnittstelle dieses Programms wird im Diagramm unten gezeigt und sie darf Hinzufügen und Auslassung sowie die Aktualisierung und das Grasen von Daten.
|
Steps to build the database application using ADO
|
Step1:The properties of all the controls are listed as follow:
|
Form Name |
frmBookTitle |
Form Caption |
Book Titles -ADOApplication |
ADO Name |
adoBooks |
Label1 Name |
lblApp |
Label1 Caption |
Book Titles |
Label 2 Name |
lblTitle |
Label2 Caption |
Title : |
Label3 Name |
lblYear |
Label3 Caption |
Year Published: |
Label4 Name |
lblISBN |
Label4 Caption |
ISBN: |
Labe5 Name |
lblPubID |
Label5 Caption |
Publisher's ID: |
Label6 Name |
lblSubject |
Label6 Caption |
Subject : |
TextBox1 Name |
txtitle |
TextBox1 DataField |
Title |
TextBox1 DataSource |
adoBooks |
TextBox2 Name |
txtPub |
TextBox2 DataField |
Year Published |
TextBox2 DataSource |
adoBooks |
TextBox3 Name |
txtISBN |
TextBox3 DataField |
ISBN |
TextBox3 DataSource |
adoBooks |
TextBox4 Name |
txtPubID |
TextBox4 DataField |
PubID |
TextBox4 DataSource |
adoBooks |
TextBox5 Name |
txtSubject |
TextBox5 DataField |
Subject |
TextBox5 DataSource |
adoBooks |
Command Button1 Name |
cmdSave |
Command Button1 Caption |
&Save |
Command Button2 Name |
cmdAdd |
Command Button2 Caption |
&Add |
Command Button3 Name |
cmdDelete |
Command Button3 Caption |
&Delete |
Command Button4 Name |
cmdCancel |
Command Button4 Caption |
&Cancel |
Command Button5 Name |
cmdPrev |
Command Button5 Caption |
&< |
Command Button6 Name |
cmdNext |
Command Button6 Caption |
&> |
Command Button7 Name |
cmdExit |
Command Button7 Caption |
E&xit |
|
Step2:
To be able to manage and access a database, you need to connect the ADO data control to a database file. We are going to use BIBLIO.MDB that comes with VB6 and to connect ADO to this database file , follow the steps below:
a) Click on the ADO control on the form and then open up the properties window.
b) Click on the ConnectionString property, the following dialog box will appear.
|
step3:
when the dialog box appear, select the Use Connection String's Option and next, click build and at the Data Link dialog box, double-Click the option labeled Microsoft Jet 3.51 OLE DB provider.
|
Step4:
After that, click the Next button to select the file BIBLO.MDB and you can click on Text Connection to ensure proper connection of the database file. Click OK to finish the connection.
Finally, click on the RecordSource property and set the command type to adCmd Table and Table name to Titles and now you are really to use the database file.
|
Step5:
Now, you need to write code for all the command buttons and after which, you can make the ADO control invisible.
|
For the Save button, the program codes are as follow:
|
Private Sub cmdSave_Click()
adoBooks.Recordset.Fields("Title") = txtTitle.Text
adoBooks.Recordset.Fields("Year Published") = txtPub.Text
adoBooks.Recordset.Fields("ISBN") = txtISBN.Text
adoBooks.Recordset.Fields("PubID") = txtPubID.Text
adoBooks.Recordset.Fields("Subject") = txtSubject.Text
adoBooks.Recordset.Update
End Sub
|
|
For the Add button, the program codes are as follow:
|
Private Sub cmdAdd_Click()
adoBooks.Recordset.AddNew
End Sub
|
|
For the Delete button, the program codes are as follow:
|
Private Sub cmdDelete_Click()
Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
If Confirm = vbYes Then
adoBooks.Recordset.Delete
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"
End If
End Sub
|
|
For the Cancel button, the program codes are as follow:
|
Private Sub cmdCancel_Click()
txtTitle.Text = ""
txtPub.Text = ""
txtPubID.Text = ""
txtISBN.Text = ""
txtSubject.Text = ""
End Sub
|
|
For the Previous (<) button, the program codes are
|
Private Sub cmdPrev_Click()
If Not adoBooks.Recordset.BOF Then
adoBooks.Recordset.MovePrevious
If adoBooks.Recordset.BOF Then
adoBooks.Recordset.MoveNext
End If
End If
End Sub
|
|
For the Next(>) button, the program codes are
|
Private Sub cmdNext_Click()
If Not adoBooks.Recordset.EOF Then
adoBooks.Recordset.MoveNext
If adoBooks.Recordset.EOF Then
adoBooks.Recordset.MovePrevious
End If
End If
End Sub
|
|
Keywords:
Creating VB database applications using ADO,
visual basic applications,
how to database,
visual basic database,
ado ms access,
ado asp net,
visual basic ado,
ado connection string,
vb ms access,
visual basic using,
microsoft access ado,
microsoft access database,
ms access database,
asp net database,
ado sql server,
ado visual basic 6,
sql server database,
vb source code,
visual basic net applications,
visual basic vb,
using sql server,
using source code
|