|
 |
aspx_beginners thread: Stored Proc to Array
Message #1 by "John Hamman {Hamman Interactive}" <johnhamman@C...> on Tue, 30 Jul 2002 18:03:03 -0400
|
|
Does anyone know how to take results from a stored proc. and put them in an
arraylist?
I cant find any samples
john
Message #2 by "Robert Sindall" <rsindall@z...> on Wed, 31 Jul 2002 09:48:53 +0100
|
|
Ok,
Why not return a Dataset for the SP... then use that?
Example:
Public Function GetContacts(ByVal moduleId As Integer) As DataSet
' Create Instance of Connection and Command Object
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim myCommand As New SqlDataAdapter("GetContacts", myConnection)
' Mark the Command as a SPROC
myCommand.SelectCommand.CommandType
CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterModuleId As New SqlParameter("@ModuleId",
SqlDbType.Int, 4)
parameterModuleId.Value = moduleId
myCommand.SelectCommand.Parameters.Add(parameterModuleId)
' Create and Fill the DataSet
Dim myDataSet As New DataSet()
myCommand.Fill(myDataSet)
' Return the DataSet
Return myDataSet
End Function
-----Original Message-----
From: John Hamman {Hamman Interactive} [mailto:johnhamman@C...]
Sent: 30 July 2002 23:03
To: aspx_beginners
Subject: [aspx_beginners] Stored Proc to Array
Does anyone know how to take results from a stored proc. and put them in an
arraylist?
I cant find any samples
john
Message #3 by "John Hamman {Hamman Interactive}" <johnhamman@C...> on Wed, 31 Jul 2002 10:02:35 -0400
|
|
Currently i am using SqlDataReader. and i run a loop in my code like below:
My new question is, is this effecent or is there a more effeciant way of
doing this? I need the abbility to
do loops. any thoughts?
Thnks
john
*****************************************************************
Dim Sitelist As hi.adminFunctions = New hi.adminFunctions()
Dim mainTable As SqlDataReader = Sitelist.GetSite(UserID)
While mainTable.Read
' do stuff
end while
****************************************************************************
***
Public Function GetMenuHeader(ByVal SiteId As Integer, ByVal depth As
Integer) As SqlDataReader
Dim cnSQL As SqlConnection
Dim cmSQL As SqlCommand
Dim drCourses As SqlDataReader
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim myCommand As New SqlCommand("Admin_GetMenuHeader",
myConnection)
myCommand.CommandType = CommandType.StoredProcedure
Dim parameterParent As New SqlParameter("@SiteId",
SqlDbType.Int, 4)
parameterParent.Value = SiteId
myCommand.Parameters.Add(parameterParent)
Dim parameterdepth As New SqlParameter("@depth", SqlDbType.Int,
4)
parameterdepth.Value = depth
myCommand.Parameters.Add(parameterdepth)
myConnection.Open()
Dim result As SqlDataReader
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Return result
End Function
-----Original Message-----
From: Robert Sindall [mailto:rsindall@z...]
Sent: Wednesday, July 31, 2002 4:49 AM
To: aspx_beginners
Subject: [aspx_beginners] RE: Stored Proc to Array
Ok,
Why not return a Dataset for the SP... then use that?
Example:
Public Function GetContacts(ByVal moduleId As Integer) As DataSet
' Create Instance of Connection and Command Object
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim myCommand As New SqlDataAdapter("GetContacts", myConnection)
' Mark the Command as a SPROC
myCommand.SelectCommand.CommandType
CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterModuleId As New SqlParameter("@ModuleId",
SqlDbType.Int, 4)
parameterModuleId.Value = moduleId
myCommand.SelectCommand.Parameters.Add(parameterModuleId)
' Create and Fill the DataSet
Dim myDataSet As New DataSet()
myCommand.Fill(myDataSet)
' Return the DataSet
Return myDataSet
End Function
-----Original Message-----
From: John Hamman {Hamman Interactive} [mailto:johnhamman@C...]
Sent: 30 July 2002 23:03
To: aspx_beginners
Subject: [aspx_beginners] Stored Proc to Array
Does anyone know how to take results from a stored proc. and put them in an
arraylist?
I cant find any samples
john
|
|
 |