Skip to main content
A newer version of this page is available.

DataAccessService.GetColumnType(Object, String, String) Method

Obtains the field type of the specified field in the data source bound to the SnapControl.

Namespace: DevExpress.Snap.Services

Assembly: DevExpress.Snap.v20.1.Core.dll

NuGet Package: DevExpress.Snap.Core

Declaration

public Type GetColumnType(
    object dataSource,
    string dataMember,
    string columnName
)

Parameters

Name Type Description
dataSource Object

An object that is the data source bound to the SnapControl.

dataMember String

A string that specifies the data member in the data source. Null (Nothing in Visual Basic) if the data source does not include data members.

columnName String

A string that is the field name.

Returns

Type Description
Type

A Type object that is the object type declaration.

Example

This example uses the DevExpress.Snap.Services.DataAccessService service to obtain the type of a field in a data source by the field name.

void ShowColumnType(object dataSource, string dataMember, string columnName)
{
    DevExpress.Snap.Services.DataAccessService srv = this.snapControl1.GetService<DevExpress.Snap.Services.DataAccessService>();
    Type type = srv.GetColumnType(dataSource, dataMember, columnName);
    if (type != null)
        MessageBox.Show(type.FullName, "Field Type Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
    else
        MessageBox.Show("Cannot determine field type", "Field Type Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

private void btnGetColumnType1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    // Get the type of the Id field in the DT1 table of the DS1 data source.
    ShowColumnType(this.snapControl1.DataSources[0].DataSource, "DT1", "Id");
}
private void btnGetColumnType2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    // Get the type of the Id field in the DT2 table of the DS2 data source.
    ShowColumnType(this.snapControl1.Document.DataSources[1].DataSource, "DT2", "Id");
}
private void btnGetColumnType3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    // Get the type of the Id field in the MyDataObjects data source.
    ShowColumnType(this.snapControl1.DataSources["MyDataObjects"].DataSource, string.Empty, "Id");
}
private void btnGetColumnType4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    // Get the type of the Id field in the table linked to the Parent table via Rel1 relation
    // in the MasterDetail data source.
    ShowColumnType(this.snapControl1.DataSources["MasterDetail"].DataSource, "Parent.Rel1", "Id");
}
See Also