Using Methods with Object Oriented Database Development with VB.NET 2005 - Developing methods with parameters as objects
(Page 4 of 5 )
In the previous section, I explained two different methods with the same name, "add." Now, I shall further extend the same class with one more method (again with the same name) with a different type of parameter, just to extend its flexibility further. Let us go through the code now:
PublicSub add(ByVal objEmp As Emp)
m_empno = objEmp.m_empno
m_ename = objEmp.m_ename
m_sal = objEmp.m_sal
m_deptno = objEmp.m_deptno
add()
End Sub
The above method will be the third method with the name "add" (but with a difference in parameters), still strengthening the "method overloading" concept. The above method accepts a different type of parameter. It is nothing but a parameter which accepts an object of the type "emp" class.
To execute the above method, you need to create a separate object of type "emp," assign values to the fields and pass the same object as a parameter, while calling the method "add." The code is shown below:
PrivateSub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Me.lblErrMsg.Text = ""
Try
Dim objParam As New Emp
With objParam
.m_deptno = Me.txtDeptno.Text
.m_empno = Me.txtEmpno.Text
.m_ename = Me.txtEname.Text
.m_sal = Me.txtSal.Text
End With
Dim ep As New Emp
ep.add(objParam)
Catch ex As Exception
Me.lblErrMsg.Text = ex.Message
End Try
End Sub
Next: Developing methods which return objects >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee