Developing a Data Access Layer for Sybase using ADO.NET: Working With Stored Procedures - Retrieving a data table by executing a Sybase stored procedure: the code
(Page 4 of 5 )
To execute a Sybase stored procedure, we again need to work with all the objects, like connection, command, adapter and so on. The following is a complete code listing for executing a stored procedure (based on the parameter cache in the previous section) at the Sybase database, which in turn returns a data table:
Public Function SPgetDataTable(ByVal ProcName As String) As
DataTable
Dim cmd As AseCommand
cmd = New AseCommand(ProcName, New AseConnection
(_ConnectionString))
Dim Parm As AseParameter
Dim privateDataTable As New DataTable
With cmd
.CommandType = CommandType.StoredProcedure
Dim UsedParameter As ASEProcParameter Dim ConvertedParameter As AseParameter
Dim drParam As DataRow
For Each drParam In dtParameterList.Rows
UsedParameter = Nothing
Dim ser As New XmlSerializer(GetType
(ASEProcParameter))
UsedParameter = CType(ser.Deserialize(New
StringReader(drParam(0))), ASEProcParameter)
ConvertedParameter =
UsedParameter.getASEParameter
.Parameters.Add(ConvertedParameter)
Next
Dim privateSQLDataAdapter As New AseDataAdapter
(cmd)
privateSQLDataAdapter.Fill(privateDataTable)
.Connection.Close()
.Dispose()
privateSQLDataAdapter.Dispose()
End With
Return privateDataTable
End Function
I excluded some code for clarity (such as exception handling). You can get the complete program from the download (available from previous articles in this series). The explanation for the above code is available in the next section.
Next: Retrieving a data table by executing a Sybase stored procedure: explanation >>
More ASP.NET Articles
More By Jagadish Chaterjee