Execute SQL that does not return data and using a transaction

You can use the IfxCommand.ExecuteNonQuery method to execute SQL statements that do not return any data

Types of SQL statements that do not return data include:
  • Inserts
  • Updates
  • Deletes
  • Creating or altering database objects

The example in this topic shows how to use IfxCommand.ExecuteNonQuery to perform an insert and also how to execute an IfxCommand inside a local transaction. For this example to work, the stores_demo database must have transaction logging. To create a stores_demo database that has transaction logging run the dbaccessdemo command with the -log option.

For the details about the IfxCommand class, see IfxCommand class. For the details about the IfxTransaction class see IfxTransaction class

try 
{
// Open a connection
IfxConnection conn = new IfxConnection(
        "Host=myhost;Service=1541;"
        + "Server=myifxserver;Database=stores_demo;"
        + "User ID=mylogin;password=mypassword"
);
conn.Open();

//Begin the transaction
IfxTransaction tx = conn.BeginTransaction();

//Create an IfxCommand that uses the connection and transaction
IfxCommand cmd = new IfxCommand(
                "INSERT INTO state VALUES('XX','No State')",
                conn,
                tx );

//Execute the command
cmd.ExecuteNonQuery();

//Commit the transaction
tx.Commit();

// Close the connection
conn.Close();
}
catch(IfxException e) 
{
Console.WriteLine(e.ToString());
Console.ReadLine(); //Wait for a Return
}