|
The web Form page
design ...
Create Visual C# .Net web Forn page ....
Classes used in this web Form page: OleDbConnection, OleDbDataAdapter, DataSet,
DataGrid, HyperLink, Panel, LinkButton, Label
1- The Access file - Web_VCnetmdb -
\\Web_VCnet\Web_VCnetmdb 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_VCnet 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_VCnet\Web_VCnetmdb.
- A data
adapter .
- A typed
dataset to hold the records fetched from
the database
|
- In the
Name box, type
Dataweb_book.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_bookdset 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_VCnetmdb -
(...\\Web_VCnet\Web_VCnetmdb) |

|
In the Connection tab, in the Select or enter
a database name box type ...\\Web_VCnet\Web_VCnetmdb 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
...
using
System; using
System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Web_VCnet
{
///
<summary>
///
Summary description for Dataweb_book.
///
</summary>
public
class Dataweb_book :
System.Web.UI.Page
{
protected
System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected
System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected
System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected
System.Data.OleDb.OleDbConnection oleDbConnection1;
protected
System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected
Web_VCnet.Dataweb_bookdset objDataweb_bookdset;
protected
System.Web.UI.WebControls.Button buttonLoad;
protected
System.Web.UI.WebControls.DataGrid masterDataGrid;
protected
System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
private
void Page_Load(object
sender, System.EventArgs e)
{
// Put user code to initialize the
page here
}
#region Web Form Designer generated code
override
protected
void OnInit(EventArgs
e)
{
//
// CODEGEN: This call is required
by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
<summary>
///
Required method for Designer support - do not modify
///
the contents of this method with the code editor.
///
</summary>
private
void
InitializeComponent()
{
this.oleDbSelectCommand1
= new
System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1
= new
System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1
= new
System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1
= new
System.Data.OleDb.OleDbCommand();
this.oleDbConnection1
= new
System.Data.OleDb.OleDbConnection();
this.oleDbDataAdapter1
= new
System.Data.OleDb.OleDbDataAdapter();
this.objDataweb_bookdset
= new
Web_VCnet.Dataweb_bookdset();
((System.ComponentModel.ISupportInitialize)( this.objDataweb_bookdset)).BeginInit();
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.CommandText
= "SELECT bookid, city, country, father_name, first_name, name FROM booknote";
this.oleDbSelectCommand1.Connection
= this.oleDbConnection1;
//
// oleDbInsertCommand1
//
this.oleDbInsertCommand1.CommandText
= "INSERT INTO booknote(city, country, father_name, first_name, name) VALUES
(?, ?, " +
"?, ?, ?)";
this.oleDbInsertCommand1.Connection
= this.oleDbConnection1;
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("city",
System.Data.OleDb.OleDbType.VarWChar, 25, "city"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("country",
System.Data.OleDb.OleDbType.VarWChar, 25, "country"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("father_name",
System.Data.OleDb.OleDbType.VarWChar, 50, "father_name"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("first_name",
System.Data.OleDb.OleDbType.VarWChar, 50, "first_name"));
this.oleDbInsertCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("name",
System.Data.OleDb.OleDbType.VarWChar, 50, "name"));
//
// oleDbUpdateCommand1
//
this.oleDbUpdateCommand1.CommandText
= @"UPDATE booknote SET city = ?, country = ?, father_name = ?, first_name =
?, name = ? WHERE (bookid = ?) AND (city = ? OR ? IS NULL AND city IS NULL)
AND (country = ? OR ? IS NULL AND country IS NULL) AND (father_name = ? OR ?
IS NULL AND father_name IS NULL) AND (first_name = ? OR ? IS NULL AND
first_name IS NULL) AND (name = ? OR ? IS NULL AND name IS NULL)";
this.oleDbUpdateCommand1.Connection
= this.oleDbConnection1;
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("city",
System.Data.OleDb.OleDbType.VarWChar, 25, "city"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("country",
System.Data.OleDb.OleDbType.VarWChar, 25, "country"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("father_name",
System.Data.OleDb.OleDbType.VarWChar, 50, "father_name"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("first_name",
System.Data.OleDb.OleDbType.VarWChar, 50, "first_name"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("name",
System.Data.OleDb.OleDbType.VarWChar, 50, "name"));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_bookid",
System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)),
((System.Byte)(0)), "bookid", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_city",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "city",
System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_city1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "city",
System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_country",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)),
"country", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_country1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)),
"country", System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_father_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "father_name",
System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_father_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "father_name",
System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_first_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "first_name",
System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_first_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "first_name",
System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "name",
System.Data.DataRowVersion.Original,
null));
this.oleDbUpdateCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "name",
System.Data.DataRowVersion.Original,
null));
//
// oleDbDeleteCommand1
//
this.oleDbDeleteCommand1.CommandText
= @"DELETE FROM booknote WHERE (bookid = ?) AND (city = ? OR ? IS NULL AND
city IS NULL) AND (country = ? OR ? IS NULL AND country IS NULL) AND (father_name
= ? OR ? IS NULL AND father_name IS NULL) AND (first_name = ? OR ? IS NULL
AND first_name IS NULL) AND (name = ? OR ? IS NULL AND name IS NULL)";
this.oleDbDeleteCommand1.Connection
= this.oleDbConnection1;
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_bookid",
System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)),
((System.Byte)(0)), "bookid", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_city",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "city",
System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_city1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "city",
System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_country",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)),
"country", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_country1",
System.Data.OleDb.OleDbType.VarWChar, 25,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)),
"country", System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_father_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "father_name",
System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_father_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "father_name",
System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_first_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "first_name",
System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_first_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "first_name",
System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_name",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "name",
System.Data.DataRowVersion.Original,
null));
this.oleDbDeleteCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_name1",
System.Data.OleDb.OleDbType.VarWChar, 50,
System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "name",
System.Data.DataRowVersion.Original,
null));
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString
= @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet
OLEDB:Database Locking Mode=1;Data Source=""C:\Documents and Settings\GERARD
ZOUEIN\VSWebCache\IBM-B5CA7BA5A3A\Web_VCnet\web_VCnet.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 Database=False;Jet
OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False";
//
// oleDbDataAdapter1
//
this.oleDbDataAdapter1.DeleteCommand
= this.oleDbDeleteCommand1;
this.oleDbDataAdapter1.InsertCommand
= this.oleDbInsertCommand1;
this.oleDbDataAdapter1.SelectCommand
= this.oleDbSelectCommand1;
this.oleDbDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new
System.Data.Common.DataTableMapping("Table", "booknote",
new
System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("bookid", "bookid"),
new
System.Data.Common.DataColumnMapping("city", "city"),
new
System.Data.Common.DataColumnMapping("country", "country"),
new
System.Data.Common.DataColumnMapping("father_name", "father_name"),
new
System.Data.Common.DataColumnMapping("first_name", "first_name"),
new
System.Data.Common.DataColumnMapping("name", "name")})});
this.oleDbDataAdapter1.UpdateCommand
= this.oleDbUpdateCommand1;
//
// objDataweb_bookdset
//
this.objDataweb_bookdset.DataSetName
= "Dataweb_bookdset";
this.objDataweb_bookdset.Locale
= new
System.Globalization.CultureInfo("en-US");
this.buttonLoad.Click
+= new
System.EventHandler(this.buttonLoad_Click);
this.Load +=
new
System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)( this.objDataweb_bookdset)).EndInit();
}
#endregion
public
void
FillDataSet(Web_VCnet.Dataweb_bookdset dataSet)
{
// 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.
this.oleDbConnection1.Open();
// Attempt to fill the dataset
through the OleDbDataAdapter1.
this.oleDbDataAdapter1.Fill(dataSet);
}
catch (System.Exception
fillException)
{
// 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.
this.oleDbConnection1.Close();
}
}
public
void 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.
Web_VCnet.Dataweb_bookdset objDataSetTemp;
objDataSetTemp = new
Web_VCnet.Dataweb_bookdset();
try
{
// Attempt to fill the temporary
dataset.
this.FillDataSet(objDataSetTemp);
}
catch (System.Exception
eFillDataSet)
{
// Add your error handling code
here.
throw
eFillDataSet;
}
try
{
// Empty the old records from the
dataset.
objDataweb_bookdset.Clear();
// Merge the records into the main
dataset.
objDataweb_bookdset.Merge(objDataSetTemp);
}
catch (System.Exception
eLoadMerge)
{
// Add your error handling code
here.
throw
eLoadMerge;
}
}
private
void
buttonLoad_Click(object
sender, System.EventArgs e)
{
try
{
this.LoadDataSet();
this.masterDataGrid.SelectedIndex
= -1;
this.masterDataGrid.DataBind();
}
catch (System.Exception
eLoad)
{
this.Response.Write(eLoad.Message);
}
}
}
}
| | |
1- |
The Properties of the web Form page -
Dataweb_book.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, 2
Label
controls, 10
LinkButton
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:
Name: ConnectionString: |
OleDbConnection1 Jet
OLEDB:Global Partial
.... | |
Note: Connection info
:
Provider =
Microsoft.Jet.OLEDB.4.0
Data source =
...\:\Web_VCnet\Web_VCnetmdb
- 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:
Name: 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_bookdset
Properties:
Name: DataSetName: |
objDataweb_bookdset Dataweb_bookdset | |
- Add the DataGrid control,
- masterDataGrid,
Properties:
(ID): SataKeyField: DataMember: DataSource: PageSize: |
masterDataGrid bookid booknote objDataweb_bookdset 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 2 Label
controls
- Label1 ,
Label Properties
(ID): Font: Text: |
Label1 Rockwell Extra Bold,
X-Large Main, Web Form Page - Visual C#
.Net | |
- lbnavigation
|
- Add 10 LinkButton
controls
- LinkButton1, LinkButton
Properties
- LinkButton2
-
Text:
2
- LinkButton3
-
Text:
3
- LinkButton4
-
Text:
4
- LinkButton5
-
Text:
5
- LinkButton6
-
Text:
6
- LinkButton7
-
Text:
7
- LinkButton8
-
Text:
8
- LinkButton9
-
Text:
9
- LinkButton10
-
Text:
10
|
| | |
***
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 |
|
|
|
|
|
|
| |