SqlCeResultSet.ResultSetView Property

Used when data binding a SqlCeResultSet to a control.

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)

public ResultSetView ResultSetView { get; }

The following example binds two textbox controls to a SqlCeResultSet by using the ResultSetView.

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;
}


Show: