This example inserts 123, 200, and null in the ex table:
// Create objects such as a connection object
HiRDBConnection pConn = new HiRDBConnection("connection-character-string");
HiRDBCommand pCom = pConn.CreateCommand();
// Connect to the database
pConn.Open();
// Create a parameter object
HiRDBParameter pPar = pCom.CreateParameter();
// Set parameters
pPar.Direction = ParameterDirection.Input;
pPar.HiRDBType = HiRDBType.Integer;
object [] aValue = new object[3];
aValue[0] = 123;
aValue[1] = 200;
aValue[2] = null;
pPar.Value = aValue;
pCom.Parameters.Add(pPar); .........................................1
// Use parameters to execute SQL statement
pCom.CommandText = "insert into ex values(?)";
pCom.ExecuteNonQuery(aValue.Length); ...............................2
// Disconnect from the database
pConn.Close(); |
- Explanation
- Set the parameter value in the value parameter. Because value is the object type, it can reference all types. The Int32 type is specified in normal INSERT statements, but in the INSERT statement using an array, the array of object is set in value, and each element of the object array is set to point to the Int32 type. The same applies when other types are used; always set an array of object in value.
- To execute the SQL statement, use :overload of ExecuteNonQuery. The normal ExecuteNonQuery has no argument, but when the INSERT statement using an array is used, specify the size of the array.
- Note
- The codes for setting value for parameters and for executing SQL statements vary depending on whether or not an array is used.