Results 1 to 3 of 3

Thread: Command object parameter refresh

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    Washington State
    Posts
    12

    Command object parameter refresh

    In classic ADO, I would use the adocommand.parameters.refresh method to return the list of arguments expected by my stored procedure. Is there a way of doing that with the sqlCommand object in .net?

  2. #2
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Whadayamean it doesn't work....
    It works fine on my machine!

  3. #3
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    you would use DeriveParameters command of the CommandBuilder object ...

    VB Code:
    1. Private Overloads Function DiscoverSpParameterSet(ByVal connection As System.Data.SqlClient.SqlConnection, _
    2.                                                       ByVal spName As String, _
    3.                                                       ByVal includeReturnValueParameter As Boolean) As System.Data.SqlClient.SqlCommand
    4.  
    5.         If (connection Is Nothing) Then Throw New ArgumentNullException("connection")
    6.         If (spName Is Nothing OrElse spName.Length = 0) Then Throw New ArgumentNullException("spName")
    7.  
    8.         Dim command As New System.Data.SqlClient.SqlCommand(spName, connection)
    9.         Dim discoveredParameters() As SqlParameter
    10.  
    11.         command.CommandType = CommandType.StoredProcedure
    12.         OpenConnection(connection)
    13.  
    14.         SqlCommandBuilder.DeriveParameters(command)
    15.  
    16.         If Not includeReturnValueParameter Then
    17.             command.Parameters.RemoveAt(0)
    18.         End If
    19.  
    20.         Dim i As Integer
    21.  
    22.         For i = 0 To command.Parameters.Count - 1
    23.             command.Parameters(i).Value = DBNull.Value
    24.         Next
    25.  
    26.         Return command
    27.  
    28.     End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width