The following procedure demonstrates how to add data to a database.
Adding rows to your database
Add the procedure below to customer.cpp, immediately before the main method:
bool do_insert( Connection * conn ) { Table * table = conn->OpenTable( UL_TEXT("ULCustomer") ); if( table == UL_NULL ) { _tprintf( _TEXT("Table not found: ULCustomer\n") ); return false; } if( table->GetRowCount() == 0 ) { _tprintf( _TEXT("Inserting one row.\n") ); table->InsertBegin(); table->Set( UL_TEXT("cust_name"), UL_TEXT("New Customer") ); table->Insert(); conn->Commit(); } else { _tprintf( _TEXT("The table has %lu rows\n"), table->GetRowCount() ); } table->Release(); return true; } |
This procedure carries out the following tasks.
The commit method is only required when autocommit is turned off. By default, autocommit is enabled, but it may be disabled for better performance, or for multi-operation transactions.
Call the do_insert method you have created.
Add the following line to the main()
method, immediately after the call to open_conn.
do_insert(conn); |
Compile your application by running nmake.
Run your application by typing customer at the command prompt.
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |