/ Home / HowTo / GetRowDataObject

How to Configure DataAccess with ConnectionBuilder.
How to Configure DataAccess with DataConfigs.

The Data Object associated with a grid row can be retrieved if the grid columns contain a unique key.

using LJCDataAccess;
using LJCDBMessage;
using LJCNetCommon;
using LJCWinFormControls;

internal void GetRowDataObject(DataAccess dataAccess
  , LJCGridRow ljcGridRow)
{
  if (ljcGridRow != null)
  {
    var name = ljcGridRow.LJCGetCellText("Name");

    var sql = $"select * from Province where Name=\'{name}\'";
    var dataTable = dataAccess.GetDataTable(sql);
    if (NetCommon.HasData(dataTable))
    {
      // Use definition for different values.
      DbColumns dataDefinition = new DbColumns()
      {
        // Property name is different from DB column name.
        { "ColumnName", "PropertyName" },
        // DataTable Column and Property name different from DB column name.
        { "ColumnName", "PropertyName", "RenameAs" }
      };

      // Create the Data Object.
      // Sets object values where DataTable column names match
      // the object property names and DataTable column row
      // values are not null.
      // If DataRow is not provided, first row is used if available.
      var converter = new ResultConverter<Province, Provinces>();
      var province = converter.CreateDataFromTable(dataTable);
        , dataDefinition: dataDefinition);
    }
  }
}
/ Home / HowTo / GetRowDataObject

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.