Contents Index Accessing and manipulating data using Dynamic SQL Data retrieval: SELECT

UltraLite ActiveX User's Guide
  Understanding UltraLite ActiveX Development
    Accessing and manipulating data using Dynamic SQL

Data manipulation: INSERT, UPDATE and DELETE


With UltraLite, you can perform INSERT, UPDATE and DELETE operations. These operations are performed using the ExecuteStatement method, a member of the ULPreparedStatement class.

For more information the ULPreparedStatement class, see ULPreparedStatement class.

UltraLite handles variable values using the ? character.

Using (?) in your prepared statements 
For any INSERT, UPDATE or DELETE, each (?) is referenced according to its ordinal position in the prepared statement. For example, the first (?) is referred to as 1, and the second as 2.

To INSERT a row

  1. Declare a ULPreparedStatement object.

    ' eMbedded Visual Basic
    Dim PS As ULPreparedStatement
    // JScript
    var PS;
  2. Assign an INSERT statement to your prepared statement object. In the following code fragment, TableName and ColumnName are the names of a table and column.

    ' eMbedded Visual Basic
    Set PS = Connection.PrepareStatement("INSERT into TableName(ColumnName) values (?)")
    // JScript
    PS = Connection.PrepareStatement("INSERT into TableName(ColumnName) values (?)");
  3. Assign values for (?) to the statement.

    ' eMbedded Visual Basic
    Dim NewValue as String
    NewValue = "Bob"
    PS.SetStringParameter 1, NewValue
    // JScript
    var NewValue;
    NewValue = "Bob";
    PS.SetStringParameter(1, NewValue);
  4. Execute the statement.

    ' eMbedded Visual Basic
    PS.ExecuteStatement
    // JScript
    PS.ExecuteStatement();

To UPDATE a row

  1. Declare a ULPreparedStatement object.

    ' eMbedded Visual Basic
    Dim PS As ULPreparedStatement
    // JScript
    var PS;
  2. Assign an UPDATE statement to your prepared statement object. In the following code fragment, TableName and ColumnName are the names of a table and column.

    ' eMbedded Visual Basic
    Set PS = Connection.PrepareStatement("UPDATE TableName SET ColumnName = (?) WHERE ID = (?)")
    // JScript
    PS = Connection.PrepareStatement("UPDATE TableName SET ColumnName = (?) WHERE ID = (?)");
  3. Assign values for (?) to the statement.

    ' eMbedded Visual Basic
    Dim NewValue as String
    NewValue = "Bob"
    PS.SetParameter 1, NewValue
    PS.SetParameter 2, "6"
    // JScript
    var NewValue;
    NewValue = "Bob";
    PS.SetParameter(1, NewValue);
    PS.SetParameter(2, "6");
  4. Execute the statement

    ' eMbedded Visual Basic
    PS.ExecuteStatement
    // JScript
    PS.ExecuteStatement();

To DELETE a row

  1. Declare a ULPreparedStatement object.

    ' eMbedded Visual Basic
    Dim PS As ULPreparedStatement
    // JScript
    var PS;
  2. Assign a DELETE statement to your prepared statement object.

    ' eMbedded Visual Basic
    Set PS = Connection.PrepareStatement("DELETE FROM customer WHERE ID = (?)")
    // JScript
    PS = Connection.PrepareStatement("DELETE FROM customer WHERE ID = (?)");
  3. Assign values for (?) to the statement.

    ' eMbedded Visual Basic
    Dim IDValue as String
    IDValue = "6"
    PS.SetParameter 1, IDValue
    // JScript
    var IDValue;
    IDValue = "6";
    PS.SetParameter( 1, IDValue );
  4. Execute the statement.

    'eMbedded Visual Basic
    PS.ExecuteStatement
    // JScript
    PS.ExecuteStatement();

Contents Index Accessing and manipulating data using Dynamic SQL Data retrieval: SELECT