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.
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 OleDbDataReaderThis will error out - Dim DataReader As New OleDbDataReaderWhile for DataAdapter you have to explicitly instantiate an object of DataAdapter Class by using NewDim objAdapter As New OleDbDataAdapterPlease 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 unlessyou set the reader to close it itself.every data retreival operation is done by DataReader in Ado.netDataAdapter is just a "wrapper class" that uses DataReader to do it's fancy stuff.Go with the flow & have fun! Else fight the flow |
 |
|
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.CloseConnectionit will automatically close it.while with dataadapter you do not worry about opening and closing the connection objectbut what it has to do with *New*? |
 |
|
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 |
 |
|
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 SomeClasscreates a new INSTANCE of an object.Dim B as SomeClasscreates a new variable that can hold a reference to an object of type SomeClass.- Jeff |
 |
|
|
|
|