Reading Data Records in an ADO.NET DataSet Example

SharePoint 2010

This C# code fragment demonstrates how to read the data records after converting a Forms2RecordDataSet to an ADO .NET DataSet. This code fragment accesses the fields of a Customizable Discussion tool, but the code can be modified to work with any Forms tool.

// First create the GrooveForms2 service, verify that the
// tool was created with a Customizable Discussion template,
// query records, and convert to ADO .NET DataSet.

// Read the forms to get table names
GrooveForms2.Form[] forms = forms2Svc.ReadForms();
for (int i = 0; i < forms.Length; i++)
{
    // Get the table for Form (if it exists)
    DataTable table = adoDs.Tables[forms[i].FormsRecordDataSet_ID];
    if (table != null)
    {
        // Read rows of table 
        for (int j = 0; j < table.Rows.Count; j++)
        {
            DataRow row = table.Rows[j];

            // Get the values of the fields
            string subject =
                (string)row["Subject"];
            string body =
                (string)row["Body"];

            // Get any attachments now
            // See example for accessing attachments
        }
    }
}

There is a convenient shortcut to find the tables in a DataSet that contain data records without knowing the names of the table. To do this, enumerate through the tables in the DataSet. If a table does not have a value for ParentRelations, then it is a table containing data records. The other tables created in the DataSet all have a value for ParentRelations. These tables are created to contain the File Attachment metadata and the File Attachment contents and to relate the data records to the File Attachments.

Community Additions

ADD
Show:
© 2014 Microsoft