Converting ADO.NET DataSet to Forms2RecordDataSet Example
Applies to: SharePoint Workspace 2010 | Visual Studio 2008
The CSharpGrooveFormsExplorer sample provided in the SDK includes the DataSet2FormsRecordDataSet function that demonstrates converting from an ADO.NET DataSet to a Forms2RecordDataSet. The following code illustrates this conversion.
private GrooveForms2.Forms2RecordDataSet DataSet2FormsRecordDataSet
(
System.Data.DataSet dataSet
)
{
GrooveForms2.Forms2RecordDataSet retVal =
new GrooveForms2.Forms2RecordDataSet();
// Translate the schema:
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
string schemaXML = dataSet.GetXmlSchema();
xmlDoc.LoadXml(schemaXML);
retVal.Schema = new System.Xml.XmlNode[] {
xmlDoc.DocumentElement };
// Translate the data:
string dataSetXML = dataSet.GetXml();
xmlDoc.LoadXml(dataSetXML);
if (xmlDoc.DocumentElement.HasChildNodes)
{
int dataNodesLength = xmlDoc.DocumentElement.ChildNodes.Count;
System.Xml.XmlNode[] dataNodes =
new System.Xml.XmlNode[dataNodesLength];
for (int i = 0; i < dataNodesLength; i++)
{
dataNodes[i] = xmlDoc.DocumentElement.ChildNodes[i];
}
retVal.Data = dataNodes;
}
else
{
retVal.Data = new object();
}
return retVal;
}
See Also
Concepts
Using ADO.NET DataSets to Access Forms2RecordDataSet Data