Click or drag to resize

DataReadpDataModel Method

Reads one record from database and fill data model class.

Namespace:  Velo.Data.Database
Assembly:  Velo.Data (in Velo.Data.dll) Version: 22.2.10.1 (22.2.10.450)
Syntax
internal static pDataModel Read<pDataModel>(
	string pSQLStatement,
	string pConnectionString = ""
)
where pDataModel : new()

Parameters

pSQLStatement
Type: SystemString
SQL statement
pConnectionString (Optional)
Type: SystemString
Database connection string

Type Parameters

pDataModel
Data model class to fill

Return Value

Type: pDataModel
Gives a data item
Remarks
Read first record from database as equal of SQL statement, example from WHERE.

The class must has a constructor method with a SQL data reader as parameter.

Examples
An example of get by ID
public static Models.BikeHistory GetByID(int pID, string pConnectionString = "")
{
    try
    {
        string lSQLStatement = Velo.Data.BikeHistory.GetSQLSelect + $" WHERE ID='{pID}';";
        return Velo.Data.Database.Data.Read<Velo.Data.Models.BikeHistory>(pSQLStatement: lSQLStatement, pConnectionString: pConnectionString);
    }
    catch (Exception lException)
    {
        //* debug information *
        System.Diagnostics.Debug.WriteLine("#Exception: " + lException.Message);
        throw;
    }
}
See Also