|
The Form design,
About.vb
Create Visual Basic
.Net Forn - About.vb
Classes used in this Form:
OleDbConnection, OleDbDataAdapter, DataSet, PictureBox, Label, TextBox, Button
- On the View menu ,
click Solution Explorer
- In Solution Explorer,
right click the APP-VBNet, select Add on the shortcut
menu to open other shortcut menu, click Add New Item, the Add
New Item - APP-VBNet dialog box appears.
- In the Add New Item -APP-VBNet
dialog box:
- In the Categories
pane, select Local Project Items
- In the Templates
pane, select Data Form Wizard . A message appears - (a form
for Windows Applications).
Note:
The Data Form Wizard
create Windows Form with data-bound controls. The controls
display data from any data source you specify. The data component for this form consists:
- A connection to a data source-(her the
datasource - C:\APP-VBNet\Pic\KJV2002.mdb.
- A data adapter .
- A typed dataset to hold the records fetched
from the database
|
- In the Name
box, type About.vb
- Click Open, the
Data Form Wizard dialog box appears.
|
the
Data Form Wizard will create a new form with data-bound
controls.
- In the 1st page of
this dialog, click Next
- In the 2nd page,
select the Create a new dataset named radioButton,
in
the box type KJV2002dset and then click Next
- In the 3rd page,
click New Connection, the Data Link Properties dialog box appears.
- In the Provider tab
of the Data Link Properties dialog box, select Microsoft
Jet 4.0 OLEDB Provider and then click Next
- In the Connection tab,
in the Select or enter a database name box type
C:\APP-VBNet\Pic\KJV2002.mdb and
then click Ok
|
and then click Next.
- In the 4th page,
pick and move the BibleTable from the Available item(s)
list to the Selected item(s) list and then click
Next
- In the 5th page,
from the Master or Single table combobox select BibleTable,
from the Columns list check only the TextData checkbox and
then click Next
- In the 6th page,
select the Single record in individual controls radio button,
uncheck (remove selected) all check boxes and then click Finish,
the do you want to include the password in the connection string dialog box appears.
In this dialog click Don't include password.
Note:
In the Windows Forms
Designer appears the design form created and in the
Properties Windows displays the corresponding properties
The design Form created ...
The Code Created ...
Public
Class
About
Inherits
System.Windows.Forms.Form
# Region
" Windows Form Designer generated code "
Public
Sub
New()
MyBase.New()
'This
call is required by the Windows Form Designer.
InitializeComponent()
'Add
any initialization after the InitializeComponent() call
End
Sub
'Form
overrides dispose to clean up the component list.
Protected
Overloads
Overrides
Sub
Dispose(ByVal
disposing As
Boolean)
If
disposing
Then
If
Not
(components Is
Nothing)
Then
components.Dispose()
End
If
End
If
MyBase.Dispose(disposing)
End
Sub
'Required by the Windows Form Designer
Private
components As
System.ComponentModel.IContainer
'NOTE:
The following procedure is required by the Windows Form
Designer
'It
can be modified using the Windows Form Designer.
'Do
not modify it using the code editor.
Friend
WithEvents
OleDbSelectCommand1 As
System.Data.OleDb.OleDbCommand
Friend
WithEvents
OleDbInsertCommand1 As
System.Data.OleDb.OleDbCommand
Friend
WithEvents
OleDbConnection1 As
System.Data.OleDb.OleDbConnection
Friend
WithEvents
OleDbDataAdapter1 As
System.Data.OleDb.OleDbDataAdapter
Friend
WithEvents
objKJV2002dset As
WindowsApplication1.KJV2002dset
Friend
WithEvents
btnLoad As
System.Windows.Forms.Button
Friend
WithEvents
btnUpdate As
System.Windows.Forms.Button
Friend
WithEvents
lblTextData As
System.Windows.Forms.Label
Friend
WithEvents
editTextData As
System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()>
Private
Sub
InitializeComponent()
Me.OleDbSelectCommand1
= New
System.Data.OleDb.OleDbCommand
Me.OleDbInsertCommand1
= New
System.Data.OleDb.OleDbCommand
Me.OleDbConnection1
= New
System.Data.OleDb.OleDbConnection
Me.OleDbDataAdapter1
= New
System.Data.OleDb.OleDbDataAdapter
Me.objKJV2002dset
= New
WindowsApplication1.KJV2002dset
Me.btnLoad
= New
System.Windows.Forms.Button
Me.btnUpdate
= New
System.Windows.Forms.Button
Me.lblTextData
= New
System.Windows.Forms.Label
Me.editTextData
= New
System.Windows.Forms.TextBox
CType(Me.objKJV2002dset,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText
= "SELECT Book, BookTitle, Chapter, TextData, Verse FROM
BibleTable"
Me.OleDbSelectCommand1.Connection
= Me.OleDbConnection1
'
'OleDbInsertCommand1
'
Me.OleDbInsertCommand1.CommandText
= "INSERT INTO BibleTable(Book, BookTitle, Chapter, TextData,
Verse) VALUES (?, ?, ?" & _
", ?, ?)"
Me.OleDbInsertCommand1.Connection
= Me.OleDbConnection1
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Book",
System.Data.OleDb.OleDbType.VarWChar, 50, "Book"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("BookTitle",
System.Data.OleDb.OleDbType.VarWChar, 50, "BookTitle"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Chapter",
System.Data.OleDb.OleDbType.VarWChar, 50, "Chapter"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("TextData",
System.Data.OleDb.OleDbType.VarWChar, 0, "TextData"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Verse",
System.Data.OleDb.OleDbType.VarWChar, 50, "Verse"))
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString
= "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry
Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data
Source=""C:\APP_VCSNet\pic\KJV2002.mdb"";" & _
"Jet OLEDB:Engine
Type=5;Jet OLEDB:Global Bulk
Transactions=1;Provider=""Microsoft" & _
".Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist
security " & _
"info=False;Extended
Properties=;Mode=Share Deny None;Jet OLEDB:Create System Dat"
& _
"abase=False;Jet
OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact
Witho" & _
"ut Replica Repair=False;User
ID=Admin;Jet OLEDB:Encrypt Database=False"
'
'OleDbDataAdapter1
'
Me.OleDbDataAdapter1.InsertCommand
= Me.OleDbInsertCommand1
Me.OleDbDataAdapter1.SelectCommand
= Me.OleDbSelectCommand1
Me.OleDbDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "BibleTable",
New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("Book", "Book"),
New
System.Data.Common.DataColumnMapping("BookTitle", "BookTitle"),
New
System.Data.Common.DataColumnMapping("Chapter", "Chapter"),
New
System.Data.Common.DataColumnMapping("TextData", "TextData"),
New
System.Data.Common.DataColumnMapping("Verse", "Verse")})})
'
'objKJV2002dset
'
Me.objKJV2002dset.DataSetName
= "KJV2002dset"
Me.objKJV2002dset.Locale
= New
System.Globalization.CultureInfo("en-US")
'
'btnLoad
'
Me.btnLoad.Location
= New
System.Drawing.Point(10, 10)
Me.btnLoad.Name
= "btnLoad"
Me.btnLoad.TabIndex
= 0
Me.btnLoad.Text
= "&Load"
'
'btnUpdate
'
Me.btnUpdate.Location
= New
System.Drawing.Point(145, 10)
Me.btnUpdate.Name
= "btnUpdate"
Me.btnUpdate.TabIndex
= 1
Me.btnUpdate.Text
= "&Update"
'
'lblTextData
'
Me.lblTextData.Location
= New
System.Drawing.Point(10, 43)
Me.lblTextData.Name
= "lblTextData"
Me.lblTextData.TabIndex
= 2
Me.lblTextData.Text
= "TextData"
'
'editTextData
'
Me.editTextData.DataBindings.Add(New
System.Windows.Forms.Binding("Text",
Me.objKJV2002dset,
"BibleTable.TextData"))
Me.editTextData.Location
= New
System.Drawing.Point(120, 43)
Me.editTextData.Name
= "editTextData"
Me.editTextData.TabIndex
= 3
Me.editTextData.Text
= ""
'
'About
'
Me.AutoScaleBaseSize
= New
System.Drawing.Size(5, 13)
Me.ClientSize
= New
System.Drawing.Size(304, 101)
Me.Controls.Add(Me.btnLoad)
Me.Controls.Add(Me.btnUpdate)
Me.Controls.Add(Me.lblTextData)
Me.Controls.Add(Me.editTextData)
Me.Name
= "About"
Me.Text
= "About"
CType(Me.objKJV2002dset,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End
Sub
# End
Region
Private
Sub
btnUpdate_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles
btnUpdate.Click
Try
'Attempt to update the datasource.
Me.UpdateDataSet()
Catch
eUpdate As
System.Exception
'Add
your error handling code here.
'Display error message, if any.
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End
Try
End
Sub
Private
Sub
btnLoad_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles
btnLoad.Click
Try
'Attempt to load the dataset.
Me.LoadDataSet()
Catch
eLoad As
System.Exception
'Add
your error handling code here.
'Display error message, if any.
System.Windows.Forms.MessageBox.Show(eLoad.Message)
End
Try
End
Sub
Public
Sub
UpdateDataSet()
'Create a new dataset to hold the changes that have been
made to the main dataset.
Dim
objDataSetChanges As
WindowsApplication1.KJV2002dset =
New
WindowsApplication1.KJV2002dset
'Stop
any current edits.
Me.BindingContext(objKJV2002dset,
"BibleTable").EndCurrentEdit()
'Get
the changes that have been made to the main dataset.
objDataSetChanges =
CType(objKJV2002dset.GetChanges,
WindowsApplication1.KJV2002dset)
'Check
to see if any changes have been made.
If (Not
(objDataSetChanges) Is
Nothing)
Then
Try
'There
are changes that need to be made, so attempt to update the
datasource by
'calling the update method and passing the dataset and any
parameters.
Me.UpdateDataSource(objDataSetChanges)
objKJV2002dset.Merge(objDataSetChanges)
objKJV2002dset.AcceptChanges()
Catch
eUpdate As
System.Exception
'Add
your error handling code here.
Throw
eUpdate
End
Try
'Add
your code to check the returned dataset for any errors that
may have been
'pushed into the row object's error.
End
If
End
Sub
Public
Sub
LoadDataSet()
'Create a new dataset to hold the records returned from the
call to FillDataSet.
'A
temporary dataset is used because filling the existing
dataset would
'require the databindings to be rebound.
Dim
objDataSetTemp As
WindowsApplication1.KJV2002dset
objDataSetTemp =
New
WindowsApplication1.KJV2002dset
Try
'Attempt to fill the temporary dataset.
Me.FillDataSet(objDataSetTemp)
Catch
eFillDataSet As
System.Exception
'Add
your error handling code here.
Throw
eFillDataSet
End
Try
Try
'Empty
the old records from the dataset.
objKJV2002dset.Clear()
'Merge
the records into the main dataset.
objKJV2002dset.Merge(objDataSetTemp)
Catch
eLoadMerge As
System.Exception
'Add
your error handling code here.
Throw
eLoadMerge
End
Try
End
Sub
Public
Sub
UpdateDataSource(ByVal
ChangedRows As
WindowsApplication1.KJV2002dset)
Try
'The
data source only needs to be updated if there are changes
pending.
If (Not
(ChangedRows) Is
Nothing)
Then
'Open
the connection.
Me.OleDbConnection1.Open()
'Attempt to update the data source.
OleDbDataAdapter1.Update(ChangedRows)
End
If
Catch
updateException As
System.Exception
'Add
your error handling code here.
Throw
updateException
Finally
'Close
the connection whether or not the exception was thrown.
Me.OleDbConnection1.Close()
End
Try
End
Sub
Public
Sub
FillDataSet(ByVal
dataSet As
WindowsApplication1.KJV2002dset)
'Turn
off constraint checking before the dataset is filled.
'This
allows the adapters to fill the dataset without concern
'for
dependencies between the tables.
dataSet.EnforceConstraints =
False
Try
'Open
the connection.
Me.OleDbConnection1.Open()
'Attempt to fill the dataset through the OleDbDataAdapter1.
Me.OleDbDataAdapter1.Fill(dataSet)
Catch
fillException As
System.Exception
'Add
your error handling code here.
Throw
fillException
Finally
'Turn
constraint checking back on.
dataSet.EnforceConstraints =
True
'Close
the connection whether or not the exception was thrown.
Me.OleDbConnection1.Close()
End
Try
End
Sub
End
Class |
|
|
- From the CD-Rom -
Teach_VNet, copy the
bmp file diam1.bmp (\\APP-VBNet\Pic\diam1.bmp) to
the folder-
c:\APP-VBNet\Pic
- On the Projet
menu , click Add Existing Item ..., Add
Existing Item - APP-VBNet dialog box appears, select the
files diam1.bmp of the folder c:\APP-VBNet\Pic,
and then click Open.
|
1. |
The
About.vb
design |
|

|
The
Properties of the Form - About.vb... |
|
Old
|
New |
Name:
Icon:
Maximize:
Menu:
Size:
Start Position:
Text:
Window State: |
About
Icon
True
(none)
400,250
WindowsDefaultLocation
About
Normal |
About
Icon
False
(none)
368,216
CenterScreen
About
Normal |
|
|
|
2. |
List of
controls created by the Data Form Wizard ...
One
OleDbConnection control, one OleDbDataAdapter control, one DataSet
control, one Label control, one TextBox control and two Button
control |
|
-
The OleDbConnection
control, created by ...
Represents an open connection to a data source
The
OleDbConnection object of the .NET Framework Data
Provider for OLE DB provides connectivity to data sources
exposed using OLE DB
The .NET Framework Data Provider for OLE DB automatically
pools connections using OLE DB session pooling. Connection
string arguments can be used to enable or disable OLE DB
services including pooling.
It is recommended that you always close
the Connection when you are finished using it
The
OleDbConnection1 Properties:
Name:
ConnectionString: |
OleDbConnection1
Jet OLEDB:Global Partial
.... |
|
Note:
Connection info :
Provider = Microsoft.Jet.OLEDB.4.0
Data source = C:\APP-VBNet\Pic\KJV2002.mdb
-
The
OleDbDataAdapter
control, created by ...
Represents a set of data commands and a database
connection that are used to fill the
DataSet and update the
data source.
The OleDbDataAdapter serves as a bridge between a
DataSet and data
source for retrieving and saving data.
The OleDbDataAdapter1Properties:
Name:
InsertCommand:
CommandText:
CommandTime:
CommandType:
Connection:
Parameters:
SelectCommand:
CommandText:
CommandTime:
CommandType: |
OleDbDataAdapter1
OleDbInsertCommand1
INSERT INTO BibleTable(Book,
BookTitle, Chapter, TextData, Verse) VALUES (?, ?,
?, ?, ?)
30
Text
OleDbConnection1
(Colection)
OleDbSelectCommand1
SELECT Book, BookTitle, Chapter,
TextData, Verse FROM BibleTable
30
Text |
|
In
OleDbDataAdapter1 Properties,
when you click Collection of Parameters
property, the OleDbParameter Collection Editor
dialog box appears
This
Editor is displayed when you are using the Properties
window to configure a data adapter on a form or component.
-
The
DataSet control, created
by ...
Datasets
store data in a disconnected cache. The structure of
a dataset is similar to that of a relational
database; it exposes a hierarchical object model of
tables, rows, and columns. In addition, it contains
constraints and relationships defined for the dataset.
The
objKJV2002dset Properties:
Name:
DataSetName: |
objKJV2002dset
KJV2002dset |
|
-
The
TextBox control, created by ...
-
EditTextData Properties:
DataBindings
Text:
Name:
BackColor:
BorderStyle:
Font:
Locked:
Multiline:
Size:
Text: |
objKJV2002dset -
BibleTable.TextData
EditTextData
Window
Fixed3D
Microsoft Sons Serief, 8.25pt
False
False
100,20
|
|
-
The Label control, created by ...
-
lblTextData Properties:
Name:
Text: |
lblTextData
TextData |
|
-
The Button control, created by ...
-
btnLoad Properties:
Name:
Size:
Text: |
btnLoad
75,23
&Load |
|
-
The Button control, created by ...
-
btnUpdate Properties:
Name:
Size:
Text: |
btnUpdate
75,23
&Update |
|
|
|
3. |
a- |
Remove the following controls created by
Wizard:
one Label
control - lbTextData and two Button controls -
btnLoad and btnUpdate
|
b- |
Modify the
Properties of the
TextBox control - EditTextData:
DataBindings
Text:
Name:
BackColor:
BorderStyle:
Font:
Locked:
Multiline:
Size: |
objKJV2002dset -
BibleTable.TextData
EditTextData
Control
None
Times New Roman, 9.75pt
True
True
264,88 |
|
Display the
1st record of the
KJV2002.mdb database Access file
|
c-- |
From
the Toolbox/Windows Form
add these controls ....
One PictureBox control, two Label
controls and two Button controls. |
|
|
-
Add the PictureBox control
-
PictureBox1, PictureBox Properties:
Name:
Image:
Size Mode: |
PictureBox1
System.Drawing.Bitmap
Autosize |
|
Bitmap file added =
C:\APP-VBNet\Pic\diam1.bmp
-
Add the Label control
-
Label1, Label Properties:
Name:
Font:
Size:
Text:
TextAlign: |
Label1
Times New
Roman, 9.75pt, style=Bold, Italic
150,16
KJV2002 database info:
TopLeft |
|
-
Add the Label control
-
Label2, Label Properties:
Name:
Font:
Size:
Text:
TextAlign: |
Label2
Times New
Roman, 9.75pt, style=Bold, Italic
150,16
developed with Visual Basic .Net
TopLeft |
|
-
Add the Label control
-
Line1, Label Properties:
Name:
BackColor:
Size:
Text: |
Line1
Windows Text
264,1
|
|
-
Add the Button control
-
btnCreated, Button Properties:
Name:
BackColor:
Size:
Text: |
btnCreated
Scrollbar
80,24
Created by |
|
-
Add the Button control
-
btnDone, Button Properties:
Name:
BackColor:
Size:
Text: |
btnDone
Scrollbar
80,24
Done |
|
|
|
|
|
About.vb
file, the codes after modification ...
The
text
Code
is
red color,
corresponding to Load data in the Statusbar control
The
text
Code is
Maroon color,
corresponding to activate the button btncreated
|
|
Public
Class
About
Inherits
System.Windows.Forms.Form
Windows Form Designer generated code |
Public
Sub
LoadDataSet()
'Create a new dataset
to hold the records returned from the call to FillDataSet.
'A temporary dataset is used
because filling the existing dataset would
'require the databindings to
be rebound.
Dim objDataSetTemp
As APP_VBNet.KJV2002dset
objDataSetTemp = New
APP_VBNet.KJV2002dset
Try
'Attempt to fill the
temporary dataset.
Me.FillDataSet(objDataSetTemp)
Catch eFillDataSet
As System.Exception
'Add your error handling
code here.
Throw eFillDataSet
End
Try
Try
'Empty the old records from
the dataset.
objKJV2002dset.Clear()
'Merge the records into the
main dataset.
objKJV2002dset.Merge(objDataSetTemp)
Catch eLoadMerge
As System.Exception
'Add your error handling
code here.
Throw eLoadMerge
End
Try
End
Sub
Public
Sub FillDataSet(ByVal
dataSet As
APP_VBNet.KJV2002dset)
'Turn off constraint
checking before the dataset is filled.
'This allows the adapters to
fill the dataset without concern
'for dependencies between
the tables.
dataSet.EnforceConstraints =
False
Try
'Open the connection.
Me.OleDbConnection1.Open()
'Attempt to fill the dataset
through the OleDbDataAdapter1.
Me.OleDbDataAdapter1.Fill(dataSet)
Catch fillException
As System.Exception
'Add your error handling
code here.
Throw fillException
Finally
'Turn constraint checking
back on.
dataSet.EnforceConstraints =
True
'Close the connection
whether or not the exception was thrown.
Me.OleDbConnection1.Close()
End
Try
End
Sub
Private
Sub About_Load(ByVal
sender As System.Object,
ByVal e
As System.EventArgs)
Handles
MyBase.Load
Try
'Attempt to load the
dataset.
Me.LoadDataSet()
Catch eLoad
As System.Exception
'Add your error handling
code here.
'Display error message, if
any.
System.Windows.Forms.MessageBox.Show(eLoad.Message)
End
Try
' StatusBar Panel 1 =
Message
fMainForm.StatusBarPanel1.Text = "Ready ... "
End
Sub
Private
Sub btnDone_Click(ByVal
sender As System.Object,
ByVal e
As System.EventArgs)
Handles btnDone.Click
'Close the connection
whether or not the exception was thrown.
Me.OleDbConnection1.Close()
' To close the current form
Me.Close()
End
Sub
Private Sub btnCreated_Click(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles btnCreated.Click
' StatusBar Panel N1 =
Message
fMainForm.StatusBarPanel1.Text = "Biography Form, moment
... "
' To Run the form -
Biography
Dim Fr As New Biography
Fr.Show()
End Sub
End
Class
|
|
|
|
|