Jump to content
Xtreme .Net Talk

Declare a new istance of object


Recommended Posts

Posted

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

  • *Gurus*
Posted

You don't use As New when you don't 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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...