Declare a new istance of object

  • Thread starter Thread starter meoabc
  • Start date Start date
M

meoabc

Guest
Hello
Im 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 dont 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 dont 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
 
You dont use As New when you dont need to create an instance
of the object at the same time you are declaring the variable. You
do use As New when you do need to create an instance of the
object, so you might just as well do it at the start. Parameters for
As New statements depend on the constructor(s) defined for the
class. Intellisense should let you know what constructors can be
used, and what the parameters (if any) can be passed.
 
Back
Top