Understanding UltraLite.NET Development
Accessing and manipulating data with the Table API
A Table object is always located at one of the following positions.
Before the first row of the table.
On a row of the table.
After the last row of the table.
If the Table object is positioned on a row, you can use one of a set of methods appropriate for the data type to retrieve or modify the value of each column.
The Table object provides a set of methods for retrieving column values. These methods take the column ID as argument.
The following code retrieves the value of the lname column, which is a character string.
// iAnywhere.Data.UltraLite namespace int lname = t.GetOrdinal( "lname" ); string lastname = t.GetString( lname );
// iAnywhere.UltraLite namespace short lname = t.Schema.GetColumnID( "lname" ); string lastname = t.GetString( lname );
The following code retrieves the value of the cust_id column, which is an integer.
// iAnywhere.Data.UltraLite namespace int cust_id = t.GetOrdinal( "cust_id" ); int id = t.GetInt( cust_id );
// iAnywhere.UltraLite namespace short cust_id = t.Schema.GetColumnID( "cust_id" ); int id = t.GetInt( cust_id );
In addition to the methods for retrieving values, there are methods for setting values. These methods take the column ID and the value as arguments.
For example, the following code sets the value of the lname column to Kaminski.
t.SetString( lname, "Kaminski" );
By assigning values to these properties you do not alter the value of the data in the database. You can assign values to the properties even if you are before the first row or after the last row of the table, but it is an error to try to access data when the current row is at one of these positions, for example by assigning the property to a variable.
// This code is incorrect t.MoveBeforeFirst(); id = t.GetInt( cust_id );
The method you choose must match the data type you wish to assign. UltraLite automatically casts database data types where they are compatible, so that you could use the getString method to fetch an integer value into a string variable, and so on.
SQL Anywhere Studio 9.0.2
Copyright © 1989–2004 Sybase, Inc. Portions copyright © 2001–2004 iAnywhere Solutions, Inc. All rights reserved.