Professional Documents
Culture Documents
Chopra ADO
Chopra ADO
Step 2: Check the database table Student in the backend MS-ACESS, the data table
contains the entries of all the students who are registered in the database. The data table
Student created in the database looks like this:
Step 3.2: Drag and Drop > OleDbDataAdapter on the Login.aspx form; it will
automatically opens the Data Adapter Configuration Wizard as follows:
2
Step 3.3: Click Next> to navigate to the next page of the Wizard which allows the user
to choose the Data Connection the user wants to open, this page looks like this:
Step 3.4: Click > New Connection Button, which then opens Data Link Properties
page to select the Microsoft Data Provider the user wants to use to connect to the
oleDbConnection. This page looks like:
Step 3.5: Select Microsoft Jet 4.0 OLE DB Provider and Click Next>>, this is the Data
Provider used for connecting to the SQL Server or MS-ACCESS databases. On
Clicking Next>> this page navigates to a new page which lets a user to Select the
database name:
Step 3.6: Click > Browse button and Select > Database one wants the application to be
connected to. In the snapshot above the database entered is the Student database named
by Gravo.mdb file placed in C:\Documents and Settings\rashic\Desktop\Gravo.mdb.
Click > Test Connection button to check whether the connection is successful. The result
is:
The Test Connection was successful, which shows that the Adapter is now connected to
the specified Database.
Step 3.7: Click OK on the Alert box to close the Data Link Properties and Click Next to
navigate to the next page, the page now looks like:
This page shows how the Data Adapter should access the database i.e. by using SQL
statements or by using stored procedures. As our application uses simple ACCESS, the
SQL statements box is already checked.
Step 3.8: Click Next > Generate SQL Statements, the page now looks like:
This page then allows the user to Generate the SQL statements using Query Builder.
Step 3.9: Click > Query Builder to navigate to the next page:
The wizard shows all the SQL statements which can be used to access the database. The
result shows that all SELECT, INSERT, UPDATE, DELETE and table mappings were
generated and the oleDbDataAdapter1 was successfully configured.
Step 3.10: Click > Finish exiting the Data Adapter Configuration Wizard. Once the
wizard is successfully configured oleDbConnection1 is automatically created at the
bottom of the Login.aspx form which looks like this:
Step 5: Open > OleDbConnection1 using the code in the Page_Load() event of the
Login.aspx.cs file using the code statement:
OleDbConnection1.Open();
Step 6: Create > DataSet by creating an instance of the DataSet class using the code
statement:
DataSet dataSet1 = new DataSet()
Step 7: Clear > DataSet before using the DataSet using the statement:
dataSet1.Clear();
Now the code looks like:
OleDbConnection1.Open();
dataSet1.Clear();
Step 9: Create > database command that represents the SQL Select statement to
execute.
It is always advisable to close the connection once the connection is used to retrieve the
data from the database.
The code for the whole connection can be seen as:
Step 13: Save > Application by Clicking Save All, to save all the files opened in the
IDE.
Step 14: Build > Application.
Step 15: Run > Application. View > Application in the browser and Click > Login
Button on the Login Page.
Step 16: Enter > MemberId: Rashi
Enter > Password: rashichopra
Conclusion: The tutorial teaches how to connect a Web Form with the database using
ADO.NET.
10