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
|
dcostelloe Level: VB Guru Registered: 11-06-2002 Posts: 74
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
(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 :-)