UpdateRespondents

Description

Updates the respondents. Missing respondents will be added.

If "inTransaction" is set to true, the update will be performed in a transaction. If an error occurs, a rollback for the whole update will be executed. Since the operation will perform a rollback if an error occurs, the return value will not have any function when the a transaction is used.
Signature
ErrorMessage[] UpdateRespondents(string key, string projectId, string uniqueKey, DataSet ds, bool inTransaction)

Parameters

Name Data Type Description

key

string required

The authentication key

projectId

string required

The projectId

uniqueKey

string required

The name of the unique key to use when updating the respondents. If set to null or an empry string, the internal id (respid) for respondents will be used.

ds

DataSet

DataSet to be Updated.

inTransaction

bool

True runs the update in a transaction, False does not.

Response

Data Type Description

Example

//***************************************************
//
// GetRespondents
// UpdateRespondents
//
//***************************************************

// The example will add a new column to the respondent data. The name of the new
// column will be "myNewColumn".
const string newColumnName = "myNewColumn";

// New instance of the SurveyData webservice.
DataTransferSoapClient dataTransfer = new DataTransferSoapClient();

RespondentToken token = null;
RespondentTransferResult result;

// Create a RespondentDataTransferDef object to get an empty list of  respondents
// from the given project.
RespondentDataTransferDef respondentDataTransferDef = new RespondentDataTransferDef
    {
        ProjectId = projectId,
        Expression = "noOfEmailsSent = -1"
    };

// Get the respondents. Run in loop while there is more data to get.
do
{
    result = dataTransfer.GetRespondents(key, respondentDataTransferDef, token);
    token = result.Token;
    DataTable dataTable = result.Result.Tables["respondent"];

    // Add a new column to the respondent data if it does not exist
    if (!dataTable.Columns.Contains(newColumnName))
    {
        dataTable.Columns.Add(new DataColumn(newColumnName));
    }

    // Create a new DataRow
    DataRow dataRow = dataTable.NewRow();
    dataRow["gender"] = "F";
    dataRow["age"] = 17;
    dataRow[newColumnName] = "my new value";
    dataRow["email"] = "dummy@dummy.com";

    // Add the new DataRow to the list or rows in the DataTable
    dataTable.Rows.Add(dataRow);

    // Make the update
    // Note that we do not include a unique key in the UpdateRespondentsGeneral call. In
    // this example we have created a new respondent that should be appended to the list of
    // respondents. Without a unique key the respondents will be appended.
    ErrorMessage[] errors = dataTransfer.UpdateRespondents(key, projectId, null, result.Result, false);

    // Check if there was any errors
    if (errors.Length > 0)
    {
        //Implement error-handling here
    }
} while (!result.Token.LastDataSet);

// Make a definition that limits to retrieve the user columns "email",
// the new column defined by the variable newColumnName, and
// the system column "respid" from all female respondents (gender="F")
respondentDataTransferDef = new RespondentDataTransferDef
{
    ProjectId = projectId,
    Expression = "gender = \"F\"",
    FieldNames = new string[] {"respid", "email", newColumnName}
};

token = null;

do
{
    // Read the specified respondents
    result = dataTransfer.GetRespondents(key, respondentDataTransferDef, token);
    token = result.Token;
    DataTable dataTable = result.Result.Tables["respondent"];

    // Change the new column for the retrieved rows
    foreach (DataRow dataRow in dataTable.Rows)
        dataRow[newColumnName] = "My female comment";

    // Make the update.
    // Note that we needed to include a unique key in the data to be able to update. In
    // this example we use the system field "respid" as the unique key. Without a unique
    // identifier in the data the respondents would be appended to the respondent list.
    ErrorMessage[] errors = dataTransfer.UpdateRespondents(key, projectId, "respid", result.Result, false);

    // Check if there was any errors
    if (errors.Length > 0)
    {
        //Implement error-handling here
    }
} while (!result.Token.LastDataSet);