wsyeager
Well-known member
Is there a way to expose the SqlDataAdapter within a TableAdapter as a Public property even after re-generating the TableAdapter?
I cant use TableAdapters, because they dont expose the SqlDataAdapter as a Public property since I need to pass down the DataAdapter to a separate DB I/O method. Not a generated DB I/O method within the TableAdapter. Im forced to use the Component Designer and create a SqlDataAdapter like I have been doing in VS.Net 2003.
The following code is generated when creating a TableAdapter:
Notice that you can set the Connection property as a Public property in the DataSet Designer, but there is no such option for the DataAdapter.
Just for kicks, I modified the code to make the DataAdapter a Public property (changed the Boldfaced Private to Public above), and was able to access it in code as follows:
The Adapter contains the associated Command objects and passes it down to the DB I/O layer performing the appropriate FILL or UPDATE command. In this case, its obviously the FILL command.
So, Microsoft should have made an option not to tie the TableAdapter to DB I/O code from within the generated code itself.
They also should include an option to make the generated DataAdapter a Public object (as seen above).
I hope this gets fixed in a service pack release. Barring this, does anybody know how I can consistently make the DataAdapter appear as a Public object?
I cant use TableAdapters, because they dont expose the SqlDataAdapter as a Public property since I need to pass down the DataAdapter to a separate DB I/O method. Not a generated DB I/O method within the TableAdapter. Im forced to use the Component Designer and create a SqlDataAdapter like I have been doing in VS.Net 2003.
The following code is generated when creating a TableAdapter:
Code:
<System.Diagnostics.DebuggerNonUserCodeAttribute()> _
Private ReadOnly Property Adapter() As System.Data.SqlClient.SqlDataAdapter
Get
If (Me._adapter Is Nothing) Then
Me.InitAdapter()
End If
Return Me._adapter
End Get
End Property
<System.Diagnostics.DebuggerNonUserCodeAttribute()> _
Public Property Connection() As System.Data.SqlClient.SqlConnection
Get
If (Me._connection Is Nothing) Then
Me.InitConnection
End If
Return Me._connection
End Get
Set
Me._connection = value
If (Not (Me.Adapter.InsertCommand) Is Nothing) Then
Me.Adapter.InsertCommand.Connection = value
End If
If (Not (Me.Adapter.DeleteCommand) Is Nothing) Then
Me.Adapter.DeleteCommand.Connection = value
End If
If (Not (Me.Adapter.UpdateCommand) Is Nothing) Then
Me.Adapter.UpdateCommand.Connection = value
End If
Dim i As Integer = 0
Do While (i < Me.CommandCollection.Length)
If (Not (Me.CommandCollection(i)) Is Nothing) Then
CType(Me.CommandCollection(i),System.Data.SqlClient.SqlCommand).Connection = value
End If
i = (i + 1)
Loop
End Set
End Property
Notice that you can set the Connection property as a Public property in the DataSet Designer, but there is no such option for the DataAdapter.
Just for kicks, I modified the code to make the DataAdapter a Public property (changed the Boldfaced Private to Public above), and was able to access it in code as follows:
Code:
Dim ta As New DataSet2TableAdapters.CustomersTableAdapter
Dim dst As New DataSet2
DataAccess.Data.SQLServerDataAccess.GetSQLData(ta.Connection, [B]ta.Adapter[/B], dst)
The Adapter contains the associated Command objects and passes it down to the DB I/O layer performing the appropriate FILL or UPDATE command. In this case, its obviously the FILL command.
So, Microsoft should have made an option not to tie the TableAdapter to DB I/O code from within the generated code itself.
They also should include an option to make the generated DataAdapter a Public object (as seen above).
I hope this gets fixed in a service pack release. Barring this, does anybody know how I can consistently make the DataAdapter appear as a Public object?
Last edited by a moderator: