Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » UltraLite - C and C++ Programming » Tutorial: Build an Application Using the C++ API

Lesson 1: Create database and connect to database Next Page

Lesson 2: Insert data into the database


The following procedure demonstrates how to add data to a database.

Adding rows to your database
  1. 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.

  2. 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);
  3. Compile your application by running nmake.

  4. Run your application by typing customer at the command prompt.