|
-
Dec 16th, 2003, 04:33 PM
#1
Thread Starter
Hyperactive Member
what does this statement means? Dim arParms() As SqlParameter = New SqlParameter(3)
Dim arParms() As SqlParameter = New SqlParameter(3) {}
-
Dec 16th, 2003, 05:36 PM
#2
Frenzied Member
It is declaring an array of 3 SqlParameters to be passed to a stored procedure.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Dec 16th, 2003, 05:42 PM
#3
4 actually since it is zero based and they are all empty parameters (no name or value).
-
Dec 16th, 2003, 05:49 PM
#4
Thread Starter
Hyperactive Member
Is there a easy way to write this statement?
Instead of having only one line...
Dim arParms() As SqlParameter = New SqlParameter(3) {}
can we break it into 2 lines?
I tried writing and it doesn't work..
dim arparms() as sqlparameter
arparms(0 = new sqlparameter(3)
any ideas please...
thanks
-
Dec 16th, 2003, 06:18 PM
#5
Why break it into 2 lines?
VB Code:
Dim arParms() As SqlParameter
arParms = New SqlParameter(3) {}
-
Dec 16th, 2003, 06:23 PM
#6
Thread Starter
Hyperactive Member
why should we use ...{} at the end?
Dim arParms() As SqlParameter
arParms = New SqlParameter(3) {}
I didn't understand the '{}' at the end of second line.
why should we use it?
-
Dec 16th, 2003, 06:40 PM
#7
The {} declare the contents of the array at declaration. Without them it will think the 3 is being passed as a parameter to the SQLParameter objects contructor. Usually you'd pass the elements of the array in the {}.
On closer inspection your code actually fills the arParms with 4 sqlparameter objects that are all set to nothing. This is because nothing is passed in the {}. So it is the same as declaring this:
VB Code:
Dim arParms(3) As SqlParameter
If you really wanted to fill the array with 4 actual objects you'd do it like this:
VB Code:
Dim arParms() As SqlParameter = {New SqlParameter, New SqlParameter, New SqlParameter, New SqlParameter}
That creates 4 instances of SqlParameters and passes them into the array.
To better illustrate the difference run this:
VB Code:
Dim arParms1() As SqlParameter = New SqlParameter(3) {}
For Each i As SqlParameter In arParms1
MsgBox(IsNothing(i), , TypeName(i))
Next
Dim arParms2() As SqlParameter = {New SqlParameter, New SqlParameter, New SqlParameter, New SqlParameter}
For Each i As SqlParameter In arParms2
MsgBox(IsNothing(i), , TypeName(i))
Next
You'll notice that the first shows each item in the array is set to nothing and actually of nothing type. Where as the second one shows they are not set to nothing and are of type SqlParameter. I'm not sure which one you need for you application but that should explain the difference.
Last edited by Edneeis; Dec 16th, 2003 at 06:44 PM.
-
Dec 16th, 2003, 06:52 PM
#8
Thread Starter
Hyperactive Member
Awesome explanation
Ed..
You are the man..The Guru...
thanks my friend.
nath
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|