SqlCeResultSet.ResultSetView 属性

在将一个 SqlCeResultSet 数据绑定到一个控件时使用。

命名空间: System.Data.SqlServerCe
程序集: System.Data.SqlServerCe(在 system.data.sqlserverce.dll 中)

语法

声明
Public ReadOnly Property ResultSetView As ResultSetView
用法
Dim instance As SqlCeResultSet
Dim value As ResultSetView

value = instance.ResultSetView
public ResultSetView ResultSetView { get; }
public:
property ResultSetView^ ResultSetView {
    ResultSetView^ get ();
}
/** @property */
public ResultSetView get_ResultSetView ()
public function get ResultSetView () : ResultSetView
不适用。

属性值

ResultSetView

示例

下面的示例通过使用 ResultSetView 将两个文本框控件绑定到一个 SqlCeResultSet 上。

Private conn As SqlCeConnection = Nothing
Private cmd As SqlCeCommand = Nothing
Private rs As SqlCeResultSet = Nothing
Private view As ResultSetView = Nothing

Private textBox1 As TextBox = Nothing
Private textBox2 As TextBox = Nothing


' NOTE: textBox instances are initialized in Form's 
' InitializeComponent() which has been omitted for the 
' brevity of this code snippet
'
Private Sub onForm_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Me.conn = New SqlCeConnection("Data Source = MyDatabase.sdf")
    Me.conn.Open()

    Me.cmd = conn.CreateCommand()
    Me.cmd.CommandText = "SELECT * FROM Orders WHERE [Order ID] < @orderID"
    Me.cmd.Parameters.Add("@orderID", SqlDbType.Int)

End Sub 'onForm_Load


Private Sub buttonBind_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Try
        ' Fill the command parameter
        '
        Me.cmd.Parameters("@orderID").Value = Me.textBox1.Text

        ' Close the previously data bound result set
        '
        If Not Nothing Is rs Then
            rs.Close()
        End If
        ' Create a new result set instance
        '
        rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable Or ResultSetOptions.Scrollable)

        ' ResultSetView implements all data binding interfaces
        '
        Me.view = rs.ResultSetView

        ' Bind to text boxes; initially these will display the first row
        '
        Me.textBox1.DataBindings.Add("text", view, "Order ID")
        Me.textBox2.DataBindings.Add("text", view, "Ship Address")

        ' Note: 
        ' While UI controls are data-bound, the associated 
        ' SqlCeResultSet and SqlCeConnection instances must
        ' remain open; 
        '
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

End Sub 'buttonBind_Click


' These event handlers are registered on the Next and Previous 
' buttons, which control which record is displayed in the data
' bound text boxes;
'
Private Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Me.BindingContext(Me.view).Position += 1

End Sub 'btnNext_Click


Private Sub btnPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Me.BindingContext(Me.view).Position -= 1

End Sub 'btnPrev_Click
SqlCeConnection conn = null;
SqlCeCommand    cmd = null;
SqlCeResultSet  rs = null;
ResultSetView   view = null;

TextBox         textBox1 = null;
TextBox         textBox2 = null;

// NOTE: textBox instances are initialized in Form's 
// InitializeComponent() which has been omitted for the 
// brevity of this code snippet
//
private void onForm_Load(object sender, System.EventArgs e)
{
    this.conn = new SqlCeConnection("Data Source = MyDatabase.sdf");
    this.conn.Open();

    this.cmd = conn.CreateCommand();
    this.cmd.CommandText = "SELECT * FROM Orders WHERE [Order ID] < @orderID";
    this.cmd.Parameters.Add("@orderID", SqlDbType.Int);
}

private void buttonBind_Click(object sender, System.EventArgs e)
{
    try
    {
        // Fill the command parameter
        //
        this.cmd.Parameters["@orderID"].Value = this.textBox1.Text;

        // Close the previously data bound result set
        //
        if (null != rs) rs.Close();

        // Create a new result set instance
        //
        rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable | 
            ResultSetOptions.Scrollable);

        // ResultSetView implements all data binding interfaces
        //
        this.view = rs.ResultSetView;

        // Bind to text boxes; initially these will display the first row
        //
        this.textBox1.DataBindings.Add("text", view, "Order ID");
        this.textBox2.DataBindings.Add("text", view, "Ship Address");

        // Note: 
        // While UI controls are data-bound, the associated 
        // SqlCeResultSet and SqlCeConnection instances must
        // remain open; 
        //
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

// These event handlers are registered on the Next and Previous 
// buttons, which control which record is displayed in the data
// bound text boxes;
//
private void btnNext_Click(object sender, System.EventArgs e)
{
    this.BindingContext[this.view].Position += 1;
}

private void btnPrev_Click(object sender, System.EventArgs e)
{
    this.BindingContext[this.view].Position -= 1;
}

平台

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

版本信息

.NET Framework

受以下版本支持:3.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

SqlCeResultSet 类
SqlCeResultSet 成员
System.Data.SqlServerCe 命名空间