R
Robert Brinson
This is a cross post originating in
microsoft.public.dotnet.languages.vb:
The company I am working for is trying to work with the Application
Data Blocks that Microsoft released to provide transparent database
connectivity for our .NET applications. I have been tasked with having
a thorough understanding of the code. However, while wading through
the source, I came across a section of code that does not make sense
to me. I was hoping that someone here would be able to enlighten me.
The code in question is in the SqlDbHelper.vb file and is under the
DiscoverSpParameterSet function:
Dim cn As New SqlConnection(connectionString)
Dim cmd As SqlCommand = New SqlCommand(spName, cn)
Dim discoveredParameters() As IDataParameter
Try
cn.Open()
cmd.CommandType = CommandType.StoredProcedure
SqlCommandBuilder.DeriveParameters(cmd)
If Not includeReturnValueParameter Then
cmd.Parameters.RemoveAt(0)
End If
discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1)
{}
cmd.Parameters.CopyTo(discoveredParameters, 0)
Finally
cmd.Dispose()
cn.Dispose()
End Try
The line I am not understanding is:
discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1) {}
I can see that an instance of a SqlParameter object is being created.
However, none of the overloaded constructors match the arguments
given. Though at the end of the statement are an opening and closing
curly brace ({}). If this is removed, I do indeed get the expected
error that I just mentioned. However, with these curly braces,
everything is fine. What is being accomplished here? Thanks in advance
for any insight you can provide. BTW, I do understand that an array is
being constructed. However, I do not understand how I am able to
instantiate a new SqlParameter without the required number of
arguments.
Robert
microsoft.public.dotnet.languages.vb:
The company I am working for is trying to work with the Application
Data Blocks that Microsoft released to provide transparent database
connectivity for our .NET applications. I have been tasked with having
a thorough understanding of the code. However, while wading through
the source, I came across a section of code that does not make sense
to me. I was hoping that someone here would be able to enlighten me.
The code in question is in the SqlDbHelper.vb file and is under the
DiscoverSpParameterSet function:
Dim cn As New SqlConnection(connectionString)
Dim cmd As SqlCommand = New SqlCommand(spName, cn)
Dim discoveredParameters() As IDataParameter
Try
cn.Open()
cmd.CommandType = CommandType.StoredProcedure
SqlCommandBuilder.DeriveParameters(cmd)
If Not includeReturnValueParameter Then
cmd.Parameters.RemoveAt(0)
End If
discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1)
{}
cmd.Parameters.CopyTo(discoveredParameters, 0)
Finally
cmd.Dispose()
cn.Dispose()
End Try
The line I am not understanding is:
discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1) {}
I can see that an instance of a SqlParameter object is being created.
However, none of the overloaded constructors match the arguments
given. Though at the end of the statement are an opening and closing
curly brace ({}). If this is removed, I do indeed get the expected
error that I just mentioned. However, with these curly braces,
everything is fine. What is being accomplished here? Thanks in advance
for any insight you can provide. BTW, I do understand that an array is
being constructed. However, I do not understand how I am able to
instantiate a new SqlParameter without the required number of
arguments.
Robert