Kamis, 23 Desember 2010

SQL object mapper - Where conditional

How to select table with WHERE codnitional

This sample codes will show how easy using SQL objects.

string connectionString = "...";

// define Person object.
Person person = new Person();

// using SQL-object to select Person table
SqlSelectFrom select = new SqlSelectFrom(person);
// set connection string
select.ConnectionString = connectionString;

// select all columns from Person table
select.Columns.All(person);

// set Where conditional FirstName = 'Andy'
select.Where.Compare(person.FirstName, CompareOperator.Equal, "Andy");

// execute select Person table
Irwsoft.Data.DataView dv = select.Execute();

// display record from DataView object
string personID_Row_1 = dv.Rows[0][person.PersonId];
string firstName_Row_1 = dv.Rows[0][person.FirstName];


Conditional :
  • // conditional personid between 1 and 5
    select.Where.Between(person.PersonId, 3, 7);
  • // conditional personid in ( 1, 2, 3, 4, 5 )
    select.Where.In(person.PersonId, 1, 2, 3, 4, 5);
  • // conditional firstname like 'Andy%'
    select.Where.Like(person.FirstName, "Andy%");
For more information click here .

Tidak ada komentar:

Posting Komentar