Home > DataLG > Code Example
.Net Articles
DataLG
Downloads
Contact

SourceForge.net Logo

OVERVIEW NEWS FUNCTIONALITIES CODE EXAMPLE Q AND A
These examples show how simple it is to select, update, insert and delete from your database objects.
To Select from a database item
The example shows how to select all products that cost under 10 dollars in the Northwind Ms Access database.
[C#]
private void ListProductsUnder10Dollars(string sDbPath)
{
    // The Operation class of the Products table
    NWIND.Tables.Products.Operation myOp;
    // The collection of Row objects that will hold
    // the result set
    NWIND.Tables.Products.Rows myRows;
    NWIND.Tables.Products.Param myParam;

    myOp = new NWIND.Tables.Products.Operation(sDbPath);

    // Instatiate the Param object that serves a criteria
    // to select only products under 10 dollars
    myParam = new NWIND.Tables.Products.Param(NWIND.Tables.Products.Field.UnitPrice,
        10, NWIND.DbOperator.LESS);

    // Select the rows using the parameter
    myOp.Select(out myRows, myParam);    

    foreach (NWIND.Tables.Products.Row myRow in myRows)
        Console.WriteLine(myRow.ProductName + " " + myRow.UnitPrice.ToString());
}

[VB]
Private Sub ListProductsUnder10Dollars(ByVal sDbPath As String)     
    ' The Operation class of the Products table
    Dim myOp As NWIND.Tables.Products.Operation
    ' The collection of Row objects that will hold
    ' the result set
    Dim myRows As NWIND.Tables.Products.Rows
    Dim myParam As NWIND.Tables.Products.Param

    myOp = New NWIND.Tables.Products.Operation(sDbPath)

    ' Instatiate the Param object that serves a criteria
    ' to select only products under 10 dollars
    myParam = New NWIND.Tables.Products.Param(NWIND.Tables.Products.Field.UnitPrice, _
        10, NWIND.DbOperator.LESS)

    ' Select the rows using the parameter
    myOp.Select(myRows, myParam)

    For Each myRow As NWIND.Tables.Products.Row In myRows
        Console.WriteLine(myRow.ProductName + " " + myRow.UnitPrice.ToString())
    Next

End Sub

To Update records in a database item
The example show how to increase all Products prices by 1 dollar.
[C#]
private void IncreaseAllProductPricesBy1Dollar(string sDbPath)
{
    NWIND.Tables.Products.Operation myOp;
    NWIND.Tables.Products.Rows myRows;

    // Instantiate the Operation class of the Products table
    myOp = new NWIND.Tables.Products.Operation(sDbPath);

    // Select the rows using the parameter
    myOp.Select(out myRows);

    // Increase the price of each product by 1 dollar
    foreach (NWIND.Tables.Products.Row myRow in myRows)
        myRow.UnitPrice += 1;

    // Update the modified records
    myOp.Update(myRows);
}

[VB]
Private Sub IncreaseAllProductPricesBy1Dollar(ByVal sDbPath As String)

    Dim myOp As NWIND.Tables.Products.Operation
    Dim myRows As NWIND.Tables.Products.Rows

    ' Instantiate the Operation class of the Products table
    myOp = New NWIND.Tables.Products.Operation(sDbPath)

    ' Select the rows using the parameter
    myOp.Select(myRows)

    ' Increase the price of each product by 1 dollar
    For Each myRow As NWIND.Tables.Products.Row In myRows
        myRow.UnitPrice += 1
    Next

    ' Update the modified records
    myOp.Update(myRows)

End Sub