ADO Tutorial (VJ++)

   

This tutorial features the new ADO/WFC.

import wfc.data.*;
public class ADOtutorial
{
public void ado_tutorial()
{
Connection conn = New Connection();
Command cmd = New Command();
Recordset rs = New Recordset();
StringBuffer str;

// Step 1—Open a connection

conn.Open("DSN=pubs;uid=sa;pwd=;database=pubs");

//Step 2—Create a command

cmd.setCommandText("SELECT * from authors");

// Step 3—Execute the command

rs.Open((Command)cmd, (Connection)conn, adOpenDymanic, 
            adLockBatchOptimistic); // enums?

// Step 4—Manipulate the data

rs.getField("au_lname").getProperties("Optimize").setBoolean(TRUE);
rs.setSort("au_lname ASCENDING");
rs.setFilter("phone LIKE '415 5*'");
rs.MoveFirst();
while(!rs.getEOF())
   {
   System.out.println("Name: " + 
            rs.getField("au_fname").getString() + " " + 
            rs.getField("au_lname").getString() + " " +
            "Phone: " + 
            rs.getField("phone").getString());

   str = rs.getField("phone").getString();
   str = str.Insert(0, "777");
   rs.getField("phone").setString(str);
   rs.MoveNext();
   }

// Step 5—Update the data

conn.beginTrans();

// Step 6, part A—Conclude the update

try
   {
   rs.updateBatch();
   conn.commitTrans();
   }

// Step 6, part B—Conclude the update

catch( Error e )
   {
   rs.setFilter(new Integer(AdoEnums.FilterGroup.CONFLICTINGRECORDS));
rs.MoveFirst();
while (!rs.getEOF())
   {
   System.out.println("Conflict: Name: " + 
            rs.getField("au_fname").getString() + " " + 
            rs.getField("au_lname").getString());
   rs.MoveNext();
   }
conn.Rollback();
}
   }
End Sub

This is the end of the VJ++ tutorial.