Gets the DbConnector which is defaultly used to load the data.
The DbConnector which is defaultly used to load the data.
The default connector is used, if no other DataConnector is provided.
By default, the DbConnector is used to connect to SqlServerCe database. If command text or connection string is set, new SqlCeCommand and SqlCeConnection, or the Command property is accessed, the command is created within the connector. If you want to use other type of access (e.g. Sql direct), you must create the object with the IDbCommand interface (SqlCommand) with the Connection set.
DbConnector exposes property Command, which can be used to manipulate with the command. It is exposed only as IDbCommand, so you have to convert the type to used command (e.g. SqlCeCommand) or use just the IDbCommand properties and methods. This is suitable for e.g. setting existing open connection to command, or manipulating the parameters of the command (see example).
This example shows the advanced usage of the DbConnector: [Visual Basic]
Sub GetFilteredData(ByVal strFilter As String)
Dim myParam As SqlCeParameter
AdvancedList1.DataRows.Clear()
' we set the existing open connection to the command
AdvancedList1.DbConnector.Command.Connection = myDatabase.myConnection
' we can use shortcut property to set the command text
advancedList1.DbConnector.CommandText =
"SELECT * FROM customers WHERE name LIKE ? "
' we can add also some parameters
' we can't use overload:
' advancedList1.DbConnector.Command.Parameters.Add("@filter", "%" + strFilter + "%")
' because we have access to IDbParameters and not to SqlCeParameters
myParam = New SqlCeParameter("@filter", "%" + strFilter + "%")
advancedList1.DbConnector.Command.Parameters.Add(myParam)
' now we use the connector to load data:
advancedList1.LoadData()
End Sub
[C#]
void GetFilteredData(string strFilter)
{
advancedList1.DataRows.Clear()
// we set the existing open connection to the command
advancedList1.DbConnector.Command.Connection = myDatabase.myConnection;
// we can use shortcut property to set the command text
advancedList1.DbConnector.CommandText =
"SELECT * FROM customers WHERE name LIKE ? ";
// we can add also some parameters
// we can't use overload:
// advancedList1.DbConnector.Command.Parameters.Add("@filter", "%" + strFilter + "%");
// because we have access to IDbParameters and not to SqlCeParameters
SqlCeParameter myParam = new SqlCeParameter("@filter", "%" + strFilter + "%");
advancedList1.DbConnector.Command.Parameters.Add(myParam);
// now we use the connector to load data:
advancedList1.LoadData();
}
AdvancedList Class | Resco.Controls.AdvancedList Namespace | DbConnector