what's the meaning...?

janilane

Active member
Joined
Jan 23, 2008
Messages
30
Programming Experience
Beginner
Not really that much familiar with object oriented, so please help me with this or kindly point me to where I can best gather info quickly. The sample below confuses me...

differences, athough sometimes they work on both...

dr1.ExecuteReader()
dr1.ExecuteReader


objects1().objects2().objects3
objects1.objects2.objects3()

...and when it is best to use:
Dim sql1 as New SqlCommand (this is creating a new object I know, but the one below is working without creating an object, so what's the use?)

against:

dim sql1 as SqlCommand


thanks
 
About the parantesis I'd be tempted to answer "who cares..?" in this VB world, and hear some laughs and some agony down the C# hall ;) You can't do this wrong without getting a meaningful error message, and the code editor usually adds these when you need them. So unless you have a more specific question regarding this issue, I'll pass this one.

As for "Dim sql1 as New SqlCommand" this is a VB shortcut for "Dim sql1 as SqlCommand = New SqlCommand", this is a three-part operation; (1) declaring a variable of type SqlCommand, (2) creating a new instance of type SqlCommand, (3) assigning the instance value (a reference) to the variable.
You would use "dim sql1 as SqlCommand" when the value/reference comes from elsewhere, like the return value of ExecuteReader method. Think about it, why would you create a new SqlCommand object when you have no use for it and ditch it the next line of code?
 
Back
Top