borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (DataGrid )Next Topic (Adding DropDownList to Custom Control) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Declare an istance of object
Poster Message
abc
Level: Guest


icon Declare an istance of object

Hello
I'm starting to learn VB.Net
When working with ADO I have to declare some objects and variables.
There are some syntax in declare statements that I don't understand, for example:

Dim Reader1 As SQLClient.SQLDataReader (1)
Dim DataAdapter As New sqlClient.SqlDataAdapter() (2)
Dim myCommand As New SqlCommand(sqlSelect, myConnection) (3)
Reader1 = New Command1.ExecuteReader (4)
.....

I don't know
- When to use "As" like in (1)
- When to use "As New"
and in this case when I can have no parameter like in (2)
or when I can have parameter like in (3)
- When to use "= New" like in (4)

Thanks for any help

16-09-2002 at 03:37 AM
| Quote Reply
dcostelloe
Level: VB Guru

Registered: 11-06-2002
Posts: 74
icon Re: Declare an istance of object

quote:
abc wrote:
Hello
I'm starting to learn VB.Net
When working with ADO I have to declare some objects and variables.
There are some syntax in declare statements that I don't understand, for example:

Dim Reader1 As SQLClient.SQLDataReader (1)
Dim DataAdapter As New sqlClient.SqlDataAdapter() (2)
Dim myCommand As New SqlCommand(sqlSelect, myConnection) (3)
Reader1 = New Command1.ExecuteReader (4)
.....

I don't know
- When to use "As" like in (1)
- When to use "As New"
and in this case when I can have no parameter like in (2)
or when I can have parameter like in (3)
- When to use "= New" like in (4)

Thanks for any help



Well to start there are books written on the subject to avoid writing a book on the subject :-)

(1)
New:
Creates a New Instance of the object

AS
Creates a instance of the object.
(2)
If I were to use the the above in ASP.Net I would use the New keyword to create a New Instance of the object for each user(Page) that calls it:
Dim ds As DataSet = New DataSet()
Each Page called will get a new instance of the object.

A good sample of variables are shown in the .Net Framework help

ms-help://MS.VSCC/MS.MSDNQTR.2002APR.1033/vbcn7/html/vacondeclaringvariables.htm

(3)
Dim myCommand As New SqlCommand(sqlSelect, myConnection)
Creates a New Instance of the object SQLCommand which now you are passing parameters to the class
(4)
Reader1 = New Command1.ExecuteReader
Your Object Reader is creating a new instance of the of the comand object and applying the values to the dataReader

Hope this Helps


____________________________
Life is but a merry go round
around and around :-)

Visit us today:
http://www.welford-costelloe.com
17-09-2002 at 11:57 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB.Net : Declare an istance of object
Previous Topic (DataGrid )Next Topic (Adding DropDownList to Custom Control) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder