SqlDataReader Class constructor

What is happening in the 3rd line of code here:
MyReader = command3.ExecuteReader(CommandBehavior.CloseConnection)
If MyReader.Read Then
     FromAddress = MyReader("Email")

Open in new window

It looks like it is calling a constructor of MyReader but I see nothing in the documentation like that.
LVL 1
allelopathAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
John (Yiannis) ToutountzoglouConnect With a Mentor Instructor Multiengine PilotCommented:
It looks like a variable to me...
it gives me the same results as  FromAddress = MyReader.Item("Email")
0
 
allelopathAuthor Commented:
You're right, that's seems to be how it works, but I don't see anything in the documentation saying that MyReader("x") is the same as MyReader.Item("x").
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
If you try i(I've tried it) to write the command and open a "(" you will see the syntax...


John (Yiannis)
0
 
käµfm³d 👽Connect With a Mentor Commented:
It's not the constructor. In VB.NET there is the concept of a default property. Such a property allows you to treat the object as it were akin to an array, and you can, in effect, index the object to return some value. In this case, the default property of the SqlDataReader class is the Item property, which gives you access to the columns the SqlDataReader got from the database. In your example, you are simply assigning the value of the "Email" column to the FromAddress variable.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.