Developing a Data Access Layer for Sybase using ADO.NET: Working With Stored Procedures
(Page 1 of 5 )
This article is third and last in a series focusing on developing a simple DAL (Data Access Layer) for any database using ADO.NET. In this series, we consider Sybase as the database of choice for developing the DAL.
I enclosed the source code in the form of a single file (“.vb” file). You can use it straight away or extend it further based on your needs. The entire discussion in this article will be based on version .NET 1.1.
If you are new to configuring Sybase for .NET or new to this series, I strongly suggest you refer to my first article of this series here.
Developing a separate class to hold all parameters of a Sybase stored procedure
In my previous two articles, you saw several methods for retrieving information from a Sybase database. In this article we shall focus on retrieving information using stored procedures available within Sybase database.
In the case of stored procedures, sometimes we may need to execute them by passing some parameters (related to the stored procedure itself). When we want to pass some parameter to a stored procedure, we need to know the parameter name, data type, size, and other details.
To hold all such information (sometimes called the parameter cache), I developed a separate class. The complete listing of the class is as follows:
<XmlRoot("SybaseProcParameter")> _
Public Class ASEProcParameter
<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
Public Sub New()
End Sub
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
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
End Class
The next section gives you a complete understanding of the class listed above.
Next: Understanding the class >>
More ASP.NET Articles
More By Jagadish Chaterjee