MobileForms Toolkit Documentation

DataConnector.Command Property

Gets or sets the IDbCommand used to retrieve data.

public virtual System.Data.IDbCommand Command {get; set;}

Property Value

IDbCommand used to retrieve data. Default value is a null reference

Remarks

The Command property must be set prior to using the DataConnector.

Note   In Compact Framework if the CommandText or the ConnectionString is set in designtime or Command is accessed in runtime and no command is supplied before, the new instance of the SqlCeCommand and the SqlCeConnection will be created.

Example

The following example shows the usage of the Command property (we can replace the SqlCeCommand with e.g. SqlCommand:

[Visual Basic]

Dim myCommand As New System.Data.SqlServerCe.SqlCeCommand("SELECT * FROM customers")
Dim myConnection As New System.Data.SqlServerCe.SqlCeConnection(_
    "DataSource = \\My Documents\\Northwind.sdf")

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)    Handles MyBase.Load
    Try
        ' set up the command for the DbConnector (not required, if set in designer)
        myCommand.Connection = myConnection
        AdvancedList1.DbConnector.Command = myCommand

        ' load the data
        AdvancedList1.LoadData()

    Catch ex As System.Data.SqlServerCe.SqlCeException
        MessageBox.Show(ex.Message)
    End Try
End Sub
            
[C#]

SqlCeCommand myCommand = new SqlCeCommand("SELECT * FROM customers");
SqlCeConnection myConnection = new SqlCeConnection("DataSource = \\My Documents\\Northwind.sdf");
    
private void Form1_Load(object sender, System.EventArgs e)
{
    try
    {
        // set up the command for the DbConnector (not required, if set in designer)
        myCommand.Connection = myConnection;
        advancedList1.DbConnector.Command = myCommand;

        // load the data
        advancedList1.LoadData();
    }
    catch(SqlCeException ex)
    {
        MessageBox.Show(ex.Message);
    }
}        
            

See Also

DataConnector Class | Resco.Controls.AdvancedList Namespace