Converting Forms2RecordDataSet to ADO.NET DataSet Example
Applies to: SharePoint Workspace 2010 | Visual Studio 2008
The CSharpGrooveFormsExplorer sample provided in the SDK includes the FormsRecordDataSet2DataSet function that demonstrates converting from a Forms2RecordDataSet to a .NET DataSet. The following code illustrates this conversion.
//Create the new .NET DataSet
private void FormsRecordDataSet2DataSet(
GrooveForms2.Forms2RecordDataSet formsRecordDataSet,
out System.Data.DataSet dataSet
)
{
dataSet = new System.Data.DataSet();
// Test whether the Schema object of the Forms2RecordDataSet input
// parameter is not null and has a type of System.Array, and
// translate the schema and data if possible:
if(formsRecordDataSet.Schema is System.Array)
{
// Read the Schema element. Create a string reader for the schema
// and then call ReadXmlSchema. Note that you need to prepend
// an XML declaration to the schema definition before calling
// ReadXmlSchema.
// Get the schema node
System.Xml.XmlNode[] schemaNodes =
(System.Xml.XmlNode[])formsRecordDataSet.Schema;
System.Xml.XmlNode schemaNode = schemaNodes[0];
// Generate a schema doc
System.Xml.XmlDocument schemaDoc = new System.Xml.XmlDocument();
schemaDoc.LoadXml(schemaNode.OuterXml);
// Load the schema
System.IO.StringReader schemaReader = new System.IO.StringReader(
"<?xml version=\"1.0\"?>"+schemaNode.OuterXml);
dataSet.ReadXmlSchema(schemaReader);
// Set the DateTimeMode property of each column whose type is
// DateTime to UTC. This has the side effect of displaying the
// values in the DataGrid as UTC as well.
// Date-time columns in .NET DataSets are considered local time by
// default. This can cause time-zone conversion problems because
// the Forms2RecordDataSet uses universal time. One method of
// avoiding this problem is to set the DateTimeMode on the column.
// You must do this after you load the schema but before you load
// the data.
foreach (System.Data.DataTable table in dataSet.Tables)
{
foreach (System.Data.DataColumn column in table.Columns)
{
if (column.DataType == typeof(System.DateTime))
{
column.DateTimeMode = System.Data.DataSetDateTime.Utc;
}
}
}
// Read the Data XML nodes using DataSet.ReadXML. Before
// translating the data, you should test whether one or more
// records are included in the Data element. If there are records,
// the Data object has a System.Array type. If there are no
// records, the Data object has a null value. If there are one or
// more records, call ReadXml for the nodes in the Data object.
if(formsRecordDataSet.Data is System.Array)
{
System.Xml.XmlNode[] dataNodes =
(System.Xml.XmlNode[])formsRecordDataSet.Data;
foreach(System.Xml.XmlNode dataNode in dataNodes)
{
System.Xml.XmlNodeReader dataNodeReader = new
System.Xml.XmlNodeReader(dataNode);
dataSet.ReadXml(dataNodeReader, System.Data.XmlReadMode.Auto);
}
}
}
}
See Also
Concepts
Using ADO.NET DataSets to Access Forms2RecordDataSet Data
Accessing Attachments in an ADO.NET DataSet Example