/ Home / HowTo / RetrieveWithSavedValues

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

Important values such as key values can be saved in an LJCDataRow for later retrieval with methods LJCSetInt32(), LJCSetInt64() and LJCSetString(). Each of these methods has a corresponding "Get" method such as LJCGetString(), etc.

using LJCDBClientLib;
using LJCDBMessage;
using LJCGridDataLib;
using LJCNetCommon;
using LJCWinFormControls;
using System.Data;

// Retrieve data using saved row values.
internal void RetrieveWithRowValues(LJCDataGrid ljcGrid
  , string connectionString, string providerName)
{
  // Create the SQLManager.
  var sqlManager = new SQLManager(null, "Province", connectionString
    , providerName);

  // Load the data and save the "ID" value in each row.
  var dataTable = sqlManager.GetDataTable();
  if (NetCommon.HasData(dataTable))
  {
     foreach (DataRow dataRow in dataTable.Rows)
    {
      var ljcGridRow = ljcGrid.LJCRowAdd();
      ljcGridRow.LJCSetInt32("ID", (int)dataRow["ID"]);
      TableData.RowSetValues(ljcGridRow, dataRow);
    }
  }

  // Retrieve the data with the saved row values.
  var ljcRow = ljcGrid.CurrentRow as LJCGridRow;
  var id = ljcRow.LJCGetInt32("ID");
  var keyColumns = new DbColumns()
  {
    { "ID" , id }
  };
  dataTable = sqlManager.GetDataTable(keyColumns);

  // 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);
}
/ Home / HowTo / RetrieveWithSavedValues

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