开发者

How Can I Expose Private Fields using a Partial Class in VB.NET?

This is my first post on Stack Overflow so please exuse (and feel free to point out) any n00b mistakes.

I am trying to implement transactions across multiple TableAdapters in VB.NET (using Visual Studio 2010) by extending the partial class as described in the following examples:

http://blah.winsmarts.com/2006/06/18/the-definitive-tableadapters--transactions-blog-post.aspx

madprops.org/blog/typed-datasets-and-sqltransaction/

stackoverflow.com/questions/2342289/net-tableadapter-to-dataadapter

However, when I attempt to expose any of the private fields created by the designer they are underlined in the editor with the following error:

'_adapter' is not declared. It may be inaccessible due to its protection level.

Searching this site as well as google has not revealed anything useful, but perhpas I'm searching the wrong keywords.

Here is the code in MyDataset.vb

Partial Public Class MyTableAdapter
    Public Property MyTransaction() As SqlTransaction
        Get
            Return _adapter.SelectCommand.Transaction
        End Get
        Set(ByVal value As SqlTransaction)
            If _adapter Is Nothing Then
                InitAdapter()
            End If
            Connection = value.Connection
            _adapter.Ins开发者_C百科ertCommand.Transaction = value
            _adapter.UpdateCommand.Transaction = value
            _adapter.DeleteCommand.Transaction = value
        End Set
    End Property

End Class

and here is the designer code:

Partial Public Class MyTableAdapter
    Inherits Global.System.ComponentModel.Component

    Private WithEvents _adapter As Global.System.Data.SqlClient.SqlDataAdapter
    Private _connection As Global.System.Data.SqlClient.SqlConnection
    Private _transaction As Global.System.Data.SqlClient.SqlTransaction
    Private _commandCollection() As Global.System.Data.SqlClient.SqlCommand

Am I missing something, or is this not possible in VB (all of the examples I've seen are in C#)?

TIA for any help!

JE


Can you access any Public properties/methods from the Adapter class?

I think you may have created your partial class in the wrong namespace. It has to be in Namespace MyDataSetTableAdapters

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜