Web Services

Insert a New Record Using External Web Service

This customization shows how to use a web service to update data from a web service-based data source. This provides an alternate way to access data than the database stored procedure and inline SQL normally generated by Iron Speed Designer.
Table Name
Select the database table
Primary Key
Select the primary key field in the table
First Updatable Field
Select an updatable field in the table
Second Updatable Field
Select another updatable field in the table
Applies to
SQLAccessClass class
/// InsertRecord makes use of Web Service to insert a record.
/// The table to insert into.
/// The record data to insert.
/// Nothing, or the new  of the inserted record.
public override BaseClasses.Data.KeyValue InsertRecord(BaseClasses.Data.TableDefinition table, BaseClasses.Data.RecordValue recVal,bool[] columnsChanged) 
    string ${First Updatable Field} = ""; 
    string ${Second Updatable Field} = ""; 

    // Get the instance of data access class.
    ${${Table Name}ClassName} my${Table Name}; 
    my${Table Name} = ${${Table Name}ClassName}.Instance; 
    foreach (BaseClasses.Data.BaseColumn col in table.ColumnList)
        int index = table.ColumnList.IndexOf(col); 
        if (col.InternalName == my${Table Name}.${First Updatable Field}Column.InternalName) 
            ${First Updatable Field} = col.ToDatabaseValue(recVal.ColumnValues[index]).ToString(); 
        else if (col.InternalName == my${Table Name}.${Second Updatable Field}Column.InternalName) 
            ${Second Updatable Field} = col.ToDatabaseValue(recVal.ColumnValues[index]).ToString(); 
        // Set the values of additional columns        
        // If a column in database allows null values, then check for null values.
        // Phone field in Shippers table allows null value. If the user does not enter any
        // value for phone while adding a new record then you need to add additional condition here.
    // Instantiate the object that will communicate with a web service.
    // Replace MyWebServiceForTableAccess with your web service name.
    localhost.MyWebServiceForTableAccess webService; 
    webService = new localhost.MyWebServiceForTableAccess();
    webService.Credentials = System.Net.CredentialCache.DefaultCredentials; 

    // Call the web service's "AddRecord" function.
    int ${Primary Key} = webService.Add${${Table Name}RecordClassName}(${First Updatable Field}, ${Second Updatable Field}); 

    // Get the id of the newly added record.
    BaseClasses.Data.KeyValue retKeyValue = new BaseClasses.Data.KeyValue(); 
    retKeyValue.AddElement(my${Table Name}.${Primary Key}Column.InternalName, ${Primary Key}.ToString()); 

    // Return the newly created id.
    return retKeyValue; 

Terms of Service Privacy Statement