Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Absolutely, newbie question

Author  Topic 

cshah1
Constraint Violating Yak Guru

347 Posts

Posted - 2005-03-14 : 12:21:00
When you instantiate an object of datareader class you do not explicitly use *New*

Dim DataReader As OleDbDataReader
This will error out - Dim DataReader As New OleDbDataReader

While for DataAdapter you have to explicitly instantiate an object of DataAdapter Class by using New

Dim objAdapter As New OleDbDataAdapter

Please advise..Thanks in advance

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-14 : 12:28:43
DataReader is created by the existing connection.
while in use you can't use the connection for anything else and you must close the connection when you're done unless
you set the reader to close it itself.
every data retreival operation is done by DataReader in Ado.net
DataAdapter is just a "wrapper class" that uses DataReader to do it's fancy stuff.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

cshah1
Constraint Violating Yak Guru

347 Posts

Posted - 2005-03-14 : 12:37:46
spirit1, tell me if I have not undetstand it properly

When you create datareader you have to explicitly open connection

objConn.Open()
and you have to also close it objConn.Close() or if you have used CommandBehavior.CloseConnection
it will automatically close it.

while with dataadapter you do not worry about opening and closing the connection object


but what it has to do with *New*?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-14 : 12:44:14
you're right.

what about new?
as i said you crete a DataAdaper because it's wrapper class.
DataReader is a initialized by SqlCommand.ExecuteReader. that's why there's no new.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-03-14 : 13:07:40
Don't confuse creating a new instance of an OBJECT, with creating a variable that will hold a reference to an existing object (or one created elsewhere).

Dim A as New SomeClass

creates a new INSTANCE of an object.

Dim B as SomeClass

creates a new variable that can hold a reference to an object of type SomeClass.

- Jeff
Go to Top of Page
   

- Advertisement -