-
Connection Objects
I was just wondering why an instance of a connection object is needed when creating a new instance of a command object
Code:
objCommand = New sqlClient.SqlCommand(strSQL, New SqlClient.SqlConnection(strConn))
but one is not need when used as a parameter to a data adapter
object.
Code:
objDA = New SqlClient.SqlDataAdapter(strSql, strConn)
objDA.fill(objDS)
-
I can only imagine it's to do with the different ways these objects are used. The DataAdapter object can open and close a connection itself which facilitates it's disconnected nature. It does this with a connection object or a connection string and it needs to be able to do this so it can operate in a disconnected mode and reconnect to the datasource when it needs to not continually.
You can also pass a command object to a dataadapter instead of a connection object/string and it's possible that forcing you to use a connection object with a command is a safety feature to ensure the dataadapter can properly use it.
Then again your guess is as good as mine and who cares anyway :)
-
Just curious. Usually one needs to create an instance of an object to work with that object. The DataAdapter probably just creates a SqlConnection internally based on the connection string passed in as a arguement. At least that's my guess. :p