Visio 2007 provides the capability to add data to your diagrams from several supported data sources such as Access, Excel, SharePoint, and SQL, etc. You can also use this capability within your Visio add-ins as the Visio object model provides many objects, methods, and properties for adding, removing, and manipulating DataRecordsets within your add-in.
Here is some sample code that demonstrates taking a .NET DataTable and adding it to a Visio drawing…
// create a new instance of our DataTable
TeamDataSet.TeamMembersDataTable data = new TeamDataSet.TeamMembersDataTable();
// read the sample data from a file to populate our data table
data.ReadXml(dataPath + "sample data.xml");
// convert the .NET DataTable to ADO Recordset XML using this class provided by the Visio 2007 SDK
string newXmlData = ADONET2ADO.ConvertToAdoRecordsetXml(data);
// create a new datarecordset in our Visio drawing using the converted XML
Visio.DataRecordset newRecordSet = this.VisioDocument.DataRecordsets.AddFromXML(newXmlData, 0, "Team Members");
Once this DataRecordset has been added to the document you can open the External Data window to view the data within your diagram and link the records in this DataRecordset to the shapes in your diagrams.
One issue I do want to point out is a small change that I made to the ADONET2ADO class that shipped with the Visio 2007 SDK. Attached to this article is an updated version of the ADONET2ADO class that contains one small fix to the TranslateType function for the System.String case. When the SDK was released this case converted System.String to ADODB.DataTypeEnum.adVarChar but this type does not handle Unicode which is very common with System.String since strings .NET are Unicode based.