IRWDataObject - .NET Object Relational Mapper
.NET Object Relational Mapper to Database

irwsoft.com


Home
IRWDataObject's code to select a record from Student - table

How to view record(s) from a single table with simple code.

string sqlConnectionString = "...";

// define view-schema for Student class
ViewSchema vs = new ViewSchema(typeof(Student), null);

// select a record with criteria Name
// define where-schema for fields Name with default value

WhereSchema ws = new WhereSchema(vs); ws.Add(SqlConditional.And, typeof(Student), typeof(Student), "Name", SqlComparison.Equal, "Andy");

// define mapper object
SelectMapper m = new SelectMapper(sqlConnectionString, vs);

// execute view-schema with new Student-object
// return value is ViewResult object

ViewResult result = m.Execute(null);

// display record from ViewResult object
foreach (ViewResultRecordInfo item in result)
{
for (int i = 0; i < vs.Columns.Length; i++)
{
Console.Write(item[vs.Columns[i].TableColumnName, vs.Columns[i].TableEntity].Value.ToString().PadLeft(25)); }
Console.WriteLine("\n");
}

Copyright by : IrwSoft © 2009 , All Rights Reserved