|
The web Form page
design ...
Create Visual Basic .Net web Forn page ....
Classes used in this web Form page: OleDbConnection, OleDbDataAdapter, DataSet,
DataGrid, HyperLink, Panel, Button, Label
1- The Access file - Web_VBnetmdb -
\\Web_VBnet\Web_VBnetmdb used by this data web form
page
2- Create
the Data Web Form page
- On the Project menu
, click Add New Item ...
- In the Add New
Item - Web_VBnet dialog box:
- In the
Categories pane, select Web Project
Items
- In the
Templates pane, select Data Form Wizard . A
message appears - (a Data form for Web
Applications)
Note:
The Data Form Wizard create Web Form
page with data-bound controls. The controls display
data from any data source you specify. The data
component for this Web form page consists:
- A
connection to a data source-(her the
datasource - \\Web_VBnet\Web_VBnetmdb.
- A data
adapter .
- A typed
dataset to hold the records fetched from
the database
|
- In the
Name box, type
Dataweb_personal.aspx
- Click Open,
the Data Form Wizard dialog box
appears.
|

|
Steps of Data Form Wizard
dialog box
... | |
the Data Form
Wizard will create a new form with data-bound
controls.
- Step 1-
In the 1st page of this dialog, click
Next |

|
- Step 2-
In the 2nd page, select the Create a new
dataset named radioButton, in the box
type Dataweb_personaldset and then click Next
|

|
- Step 3-
In the 3rd page, click New Connection,
the Data Link Properties dialog box
appears. |

|
Data Link Properties dialog
box |
|
In the Provider tab of the Data Link
Properties dialog box, select Microsoft Jet 4.0 OLEDB
Provider and then click Next
|

|
Uses the Select Assecc DataBase dialog
box to select the database file Web_VBnetmdb -
(...\\Web_VBnet\Web_VBnetmdb) |

|
In the Connection tab, in the Select or enter
a database name box type ...\\Web_VBnet\Web_VBnetmdb and then click
Ok |

|
|
|
and then click Next. |

|
- Step 4-
In the 4th page, pick and move the book
from the Available item(s) list to the Selected
item(s) list and then click Next |
 |
- Step 5 -
In the 5th page, from the Master or Single
table combobox select , from the Columns list check all
Checkboxes and then click Finish. |
 |
- Step 6 -
-
The
do you want to include the password in the connection
string dialog box appears. In this dialog click
Don't include password. |

|
In the
Windows Designer appears the design web form
created The design Form created ...
The Code Created
...
Public
Class
Dataweb_personal
Inherits System.Web.UI.Page
# Region
" Web Form Designer Generated Code "
'This call is
required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private
Sub
InitializeComponent()
Me.OleDbSelectCommand1
= New
System.Data.OleDb.OleDbCommand
Me.OleDbInsertCommand1
= New
System.Data.OleDb.OleDbCommand
Me.OleDbUpdateCommand1
= New
System.Data.OleDb.OleDbCommand
Me.OleDbDeleteCommand1
= New
System.Data.OleDb.OleDbCommand
Me.OleDbConnection1
= New
System.Data.OleDb.OleDbConnection
Me.OleDbDataAdapter1
= New
System.Data.OleDb.OleDbDataAdapter
Me.objDataweb_personaldset
= New
Web_VBnet.Dataweb_personaldset
CType(Me.objDataweb_personaldset,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText
= "SELECT birth, country, first_name, name, personal_id,
sex FROM personal"
Me.OleDbSelectCommand1.Connection
= Me.OleDbConnection1
'
'OleDbInsertCommand1
'
Me.OleDbInsertCommand1.CommandText
= "INSERT INTO personal(birth, country, first_name, name,
sex) VALUES (?, ?, ?, ?, ?" & _
")"
Me.OleDbInsertCommand1.Connection
= Me.OleDbConnection1
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("birth",
System.Data.OleDb.OleDbType.DBDate, 0, "birth"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("country",
System.Data.OleDb.OleDbType.VarWChar, 25, "country"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("first_name",
System.Data.OleDb.OleDbType.VarWChar, 50, "first_name"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("name",
System.Data.OleDb.OleDbType.VarWChar, 50, "name"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("sex",
System.Data.OleDb.OleDbType.VarWChar, 25, "sex"))
'
'OleDbUpdateCommand1
'
Me.OleDbUpdateCommand1.CommandText
= "UPDATE personal SET birth = ?, country = ?, first_name
= ?, name = ?, sex = ? WHE" & _
"RE (personal_id = ?) AND (birth = ? OR ? IS NULL AND
birth IS NULL) AND (country" & _
" = ? OR ? IS NULL AND country IS NULL) AND (first_name
= ? OR ? IS NULL AND firs" & _
"t_name IS NULL) AND (name = ? OR ? IS NULL AND name IS
NULL) AND (sex = ? OR ? I" & _
"S NULL AND sex IS NULL)"
Me.OleDbUpdateCommand1.Connection
= Me.OleDbConnection1
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("birth",
System.Data.OleDb.OleDbType.DBDate, 0, "birth"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("country",
System.Data.OleDb.OleDbType.VarWChar, 25, "country"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("first_name",
System.Data.OleDb.OleDbType.VarWChar, 50, "first_name"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("name",
System.Data.OleDb.OleDbType.VarWChar, 50, "name"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("sex",
System.Data.OleDb.OleDbType.VarWChar, 25, "sex"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_personal_id",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"personal_id", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_birth",
System.Data.OleDb.OleDbType.DBDate, 0,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"birth", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_birth1",
System.Data.OleDb.OleDbType.DBDate, 0,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"birth", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_country",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"country", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_country1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"country", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_first_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"first_name", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_first_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"first_name", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"name", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"name", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_sex",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"sex", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_sex1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"sex", System.Data.DataRowVersion.Original,
Nothing))
'
'OleDbDeleteCommand1
'
Me.OleDbDeleteCommand1.CommandText
= "DELETE FROM personal WHERE (personal_id = ?) AND (birth
= ? OR ? IS NULL AND birt" & _
"h IS NULL) AND (country = ? OR ? IS NULL AND country
IS NULL) AND (first_name = " & _
"? OR ? IS NULL AND first_name IS NULL) AND (name = ?
OR ? IS NULL AND name IS NU" & _
"LL) AND (sex = ? OR ? IS NULL AND sex IS NULL)"
Me.OleDbDeleteCommand1.Connection
= Me.OleDbConnection1
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_personal_id",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"personal_id", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_birth",
System.Data.OleDb.OleDbType.DBDate, 0,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"birth", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_birth1",
System.Data.OleDb.OleDbType.DBDate, 0,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"birth", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_country",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"country", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_country1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"country", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_first_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"first_name", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_first_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"first_name", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"name", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"name", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_sex",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"sex", System.Data.DataRowVersion.Original,
Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_sex1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
False,
CType(0,
Byte),
CType(0,
Byte),
"sex", System.Data.DataRowVersion.Original,
Nothing))
'
'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:\Documents and
Settings\GERARD ZOUEIN\VSWebCache\I" & _
"BM-B5CA7BA5A3A\Web_VBnet\web_VBnet.mdb"";Jet
OLEDB:Engine Type=5;Jet OLEDB:Global" & _
" Bulk
Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet
OLEDB:System databas" & _
"e=;Jet OLEDB:SFP=False;persist security info=False;Extended
Properties=;Mode=Sha" & _
"re Deny None;Jet OLEDB:Create System Database=False;Jet
OLEDB:Don't Copy Locale " & _
"on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;User ID=Admin;Je" & _
"t OLEDB:Encrypt Database=False"
'
'OleDbDataAdapter1
'
Me.OleDbDataAdapter1.DeleteCommand
= Me.OleDbDeleteCommand1
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", "personal",
New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("birth", "birth"),
New
System.Data.Common.DataColumnMapping("country",
"country"), New
System.Data.Common.DataColumnMapping("first_name", "first_name"),
New
System.Data.Common.DataColumnMapping("name", "name"),
New
System.Data.Common.DataColumnMapping("personal_id", "personal_id"),
New
System.Data.Common.DataColumnMapping("sex", "sex")})})
Me.OleDbDataAdapter1.UpdateCommand
= Me.OleDbUpdateCommand1
'
'objDataweb_personaldset
'
Me.objDataweb_personaldset.DataSetName
= "Dataweb_personaldset"
Me.objDataweb_personaldset.Locale
= New
System.Globalization.CultureInfo("en-US")
CType(Me.objDataweb_personaldset,
System.ComponentModel.ISupportInitialize).EndInit()
End
Sub
Protected
WithEvents
OleDbSelectCommand1
As System.Data.OleDb.OleDbCommand
Protected
WithEvents
OleDbInsertCommand1
As System.Data.OleDb.OleDbCommand
Protected
WithEvents
OleDbUpdateCommand1
As System.Data.OleDb.OleDbCommand
Protected
WithEvents
OleDbDeleteCommand1
As System.Data.OleDb.OleDbCommand
Protected
WithEvents
OleDbConnection1 As
System.Data.OleDb.OleDbConnection
Protected
WithEvents
OleDbDataAdapter1 As
System.Data.OleDb.OleDbDataAdapter
Protected
WithEvents
objDataweb_personaldset
As
Web_VBnet.Dataweb_personaldset
Protected
WithEvents
buttonLoad As
System.Web.UI.WebControls.Button
Protected
WithEvents
masterDataGrid As
System.Web.UI.WebControls.DataGrid
'NOTE: The
following placeholder declaration is required by the Web
Form Designer.
'Do not delete or
move it.
Private
designerPlaceholderDeclaration
As
System.Object
Private
Sub
Page_Init(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles
MyBase.Init
'CODEGEN: This
method call is required by the Web Form Designer
'Do not modify it
using the code editor.
InitializeComponent()
End
Sub
# End
Region
Private
Sub
Page_Load(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles
MyBase.Load
'Put user code to
initialize the page here
End
Sub
Private
Sub
buttonLoad_Click(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles buttonLoad.Click
Try
Me.LoadDataSet()
Me.masterDataGrid.SelectedIndex
= -1
Me.masterDataGrid.DataBind()
Catch
eLoad As
System.Exception
Me.Response.Write(eLoad.Message)
End
Try
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
Web_VBnet.Dataweb_personaldset
objDataSetTemp =
New Web_VBnet.Dataweb_personaldset
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.
objDataweb_personaldset.Clear()
'Merge the
records into the main dataset.
objDataweb_personaldset.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
Web_VBnet.Dataweb_personaldset)
'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 | | |
1- |
The Properties of the web Form page -
Dataweb_personal.aspx.
 |
|
Document
Properties | |
|
|
2- |
List of controls created by
the Data Form Wizard or
from the
Toolbox..
1 OleDbConnection
control, 1 OleDbDataAdapter control, 1 DataSet control,
1 DataGrid
control,, 1
HyperLink
control, 1
Panel
control, 5
Button
controls,
7 Label
controls |
|
- 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:
(ID): ConnectionString: |
OleDbConnection1 Jet
OLEDB:Global Partial
.... | |
Note: Connection info
:
Provider =
Microsoft.Jet.OLEDB.4.0
Data source =
C:\Web_VBnet\data\Web_VBnetmdb
- 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
OleDbDataAdapter1 Properties:
(ID): InsertCommand:
CommandText:
CommandTime:
CommandType: Connection: Parameters: SelectCommand:
CommandText:
CommandTime:
CommandType: |
OleDbDataAdapter1 OleDbInsertCommand1 INSERT
INTO
... 30 Text OleDbConnection1 (Collection) OleDbSelectCommand1 SELECT
.... 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 web Form page 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 objDataweb_personaldset
Properties:
(ID): DataSetName: |
objDataweb_personaldset
Dataweb_personaldset | |
- Add the DataGrid control,
- masterDataGrid,
Properties:
(ID):
SataKeyField:
DataMember:
DataSource: PageSize: |
masterDataGrid
bookid
booknote
objDataweb_personaldset 5 | |
- Add the HyperLink
control -
HyperLink2
Properties
(ID): NavigateUrl:
Text: |
HyperLink2 WebForm1.aspx
return to main | |
- Add Panel
control - Panel1
Properties
(ID): BackColor:
Width: |
Panel1
Olive
877px |
|
- Add 5 Botton
controls
- FirstPage, Button
Properties
(ID): Text: |
FirstPage First | |
- PreviousPage
- Text: Prev.
- NextPage
- Text: Next
- LastPage
- Text: Last
|
- Add 7 Label
controls
- Label1, Label
Properties
(ID): Font: Text: |
Label1
Rockwell Extra Bold, X-Large Main, Web Form
Page - Visual Basic .Net | |
- Label_nav1
-
Label_nav2
- Label_add1
- Label_add2
- Label_addinfo
- lbnavigation
|
| | |
***
Note
To work
probably this Data Web Form , it's necessary to add the
following text to the file Web.Config -
(<identity impersonate="true"/>)
- Look
this file |
|
|
|
|
|
|
| |