Connect to the iLab here.

Connect to the iLab here.

Lab 3 of 7: Create and Use a Web Service

L A B O V E R V I E W

Scenario/Summary
In this iLab, your will connect to MS Access database to lookup an employee address by Last Name. To do such, we will be creating a Web Service to call in our application and implement the Find feature.
Deliverables
The 7 tasks you will need to do for this week’s lab are:
Create a Web Services class (5 points)
Add dataset to your project and create a function for the Web Services (10 points)
Add controls to the form (8 points, 2 points each)
Add the function in the web form to call the service method ( 15 points)
Finalize the iLab
Take a screen capture of your final output (2 points)
ZIP and submit the entire web project.

L A B S T E P S

STEP 1: Create a Web Service class

Create a Web Service called “clsWebServices”.
Right click on your lab location, choose “add new item” then Web Service.
STEP 2: Create a function for the Web Service

Add a dsAddress dataset to your project as shown below.
Copy the MS Access database, AddressBook.mdb, to your application folder. You can find the database in Doc Sharing. Note that you can have the database at any location on your computer, but your code should be adjusted accordingly. From the Solution Explorer, right click on the App_Code folder, and select “Add New Item” menu option. The Dialog below shows. Select DataSet and type the dsAddress as the name of the dataset.

Make sure to set the Data Source to “Microsoft Access Database File” as shown below

Provide the “Select” statement whose result will be used to populate the DataSet as shown below.

After you are done adding the “dsAddress” Dataset object, in the clsWebService class, create a function, web method, called “FindAddress” which accepts the following parameters: LastName and Path.
Double-click the blank space in clsWebServices to get to the code designer. Add the following code. Type comments for each step being performed.

‘ Add your comments here
Imports System.Data
Imports System.Data.OleDb

_
Public Function FindAddress(ByVal LastName As String, ByVal Path As String)As dsAddress
‘ Add your comments here
Dim DS As dsAddress
Dim sqlConn As OleDbConnection
Dim sqlDA As OleDbDataAdapter
‘ Add your comments here
sqlConn = New OleDbConnection(“PROVIDER=Microsoft.Jet.OLEDB.4.0;” & _
“Data Source=” & Path & “”)
‘ Add your comments here
sqlDA = New OleDbDataAdapter(“select * from tblAddressBook where LastName like ‘” & LastName & “‘”, sqlConn)
‘ Add your comments here
DS = New dsAddress
‘ Add your comments here
sqlDA.Fill(DS.tblAddressBook)
‘ Add your comments here
Return DS
End Function
STEP 3: Add controls to the form

Add to frmAddressBook one Label, one TextBox, and one Button having the following properties:

Object
Property
Value to set
Label1
Text
Find Last Name:
TextBox1
[ID]
txtFindLastName
Button1
[ID]
btnFindLastName
Button1
Text
Find Last Name:
Text2
[ID]
txtFirstName
Text3
[ID]
txtLastName
Text4
[ID]
txtEmail
Text5
[ID]
txtPhoneNumber
Label2
Text
First Name
Label3
Text
Last Name
Label4
Text
Email
Label5
Text
Phone Number
Label6
[ID]
lblMessage
The web form layout looks similar to what is shown below

STEP 4: Add the function in the web form to call the service method

Modify the btnFindByLastName click() to call the Web Service FindAddress ().
Double-click btnFindByLastName to get to the code designer. Add the following code:
Private Sub btnFindLastName_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles btnFindLastName.Click

Try
Dim serviceObj As New clsWebServices
‘ Add your comments here
Dim dsFindLastName As New dsAddress
Dim TempPath As New String
TempPath = Server.MapPath(“AddressBook.mdb”) ‘Add your commentes here
‘ Add your comments here
dsFindLastName = serviceObj.FindAddress(Me.txtFindLastName.Text, TempPath)
‘Add your comments here
If dsFindLastName.tblAddressBook.Rows.Count > 0 Then
‘ Add your comments here
Me.txtFirstName.Text = dsFindLastName.tblAddressBook(0).FirstName.ToString
Me.txtLastName.Text = dsFindLastName.tblAddressBook(0).LastName.ToString
Me.txtEmail.Text = dsFindLastName.tblAddressBook(0).Email.ToString
Me.txtPhoneNumber.Text = dsFindLastName.tblAddressBook(0).PhoneNumber.ToString
Else
lblMessage.Text = “No records were found!!”
End If

Catch ex As Exception
‘ Add your comments here
lblMessage.Text = ex.Message
End Try
End Sub
Remember to add comments for each step being performed.
STEP 5: Finalize the iLab

Save your work! Test it! Make changes as appropriate until it works.
Note
Throughout the course, you will see small images. Click these small images to bring up larger versions, then click the larger versions to return to the course.

STEP 6: Take a screen capture of your final output

After you complete your work for t

WEB/460A WEB460A WEB-460A WEB460 A WEB 460 A
WEB/460B WEB460B WEB-460B WEB460 B WEB 460 B
WEB/460C WEB460C WEB-460C WEB460 C WEB 460 C
WEB/460D WEB460D WEB-460D WEB460 D WEB 460 D
Lab3 Lab 3 Week 3 Week3 Week3 Lab iLab3 of 7
–iqrajavaid

Use the order calculator below and get started! Contact our live support team for any assistance or inquiry.

[order_calculator]