Developing a Data Access Layer for Sybase using ADO.NET: Working With Stored Procedures - Understanding the class
(Page 2 of 5 )
This section explains the class listed in the previous section. Let us go through it part by part. First of all, consider the following:
<XmlRoot("SybaseProcParameter")> _
Public Class ASEProcParameter
The name of the class is “ASEProcPrameter” (user-defined). If we wanted to have this class serialized, the root of the XML would start at the “SybaseProcParameter” element. Even though for the above, serialization is not necessary, there are times when you want to pass the parameters between several tiers of your application. Then you need to serialize the information before you do marshaling or un-marshaling. In the above case, it would be automatically serialized to XML! Further proceeding, we have the following:
<XmlElement("ParameterName", GetType(String))> _
Public ParameterName As String
<XmlElement("ParameterValue", GetType(Object))> _
Public ParameterValue As Object
<XmlElement("ParameterDataType", GetType(AseDbType))> _
Public ParameterDataType As AseDbType
<XmlElement("ParameterSize", GetType(Integer))> _
Public ParameterSize As Integer
<XmlElement("ParameterDirectionUsed", GetType
(ParameterDirection))> _
Public ParameterDirectionUsed As ParameterDirection
Those are all the class level variables needed to hold the parameter information of a stored procedure. I hope the name is reasonable and you can follow accordingly. Further proceeding, we have the following:
Public Sub New(ByVal passedParameterName As String, _
ByVal passedValue As Object, _
Optional ByVal passedSQLType As AseDbType = Nothing,
_
Optional ByVal passedSize As Integer = Nothing, _
Optional ByVal passedDirection As ParameterDirection
= ParameterDirection.Input)
ParameterName = passedParameterName
ParameterValue = passedValue
ParameterDataType = passedSQLType
ParameterSize = passedSize
ParameterDirectionUsed = passedDirection
End Sub
The above code fragment is a constructor which accepts certain information of a single parameter and passes the information to the class level variables. Further proceeding we have:
Public Function getASEParameter() As AseParameter
Dim returnSQLParameter As AseParameter = New AseParameter
returnSQLParameter.ParameterName = ParameterName
returnSQLParameter.Value = ParameterValue
returnSQLParameter.AseDbType = ParameterDataType
returnSQLParameter.Size = ParameterSize
returnSQLParameter.Direction = ParameterDirectionUsed
Return returnSQLParameter
End Function
The above is very similar to the translation of our existing parameter information to the Sybase understandable parameter.
Next: Adding a parameter before executing a Sybase stored procedure >>
More ASP.NET Articles
More By Jagadish Chaterjee