private void bLoad_Click(object sender, System.EventArgs e) { // Load the data from the SQL; we append the data to what already exists try { // Obtain the connection information XmlNode rNode = _Draw.GetReportNode(); XmlNode dsNode = _Draw.GetNamedChildNode(rNode, "DataSources"); if (dsNode == null) { return; } XmlNode datasource = null; foreach (XmlNode dNode in dsNode) { if (dNode.Name != "DataSource") { continue; } XmlAttribute nAttr = dNode.Attributes["Name"]; if (nAttr == null) // shouldn't really happen { continue; } if (nAttr.Value != _dsv.DataSourceName) { continue; } datasource = dNode; break; } if (datasource == null) { MessageBox.Show(string.Format("Datasource '{0}' not found.", _dsv.DataSourceName), "Load Failed"); return; } // get the connection information string connection = ""; string dataProvider = ""; string dataSourceReference = _Draw.GetElementValue(datasource, "DataSourceReference", null); if (dataSourceReference != null) { // This is not very pretty code since it is assuming the structure of the windows parenting. // But there isn't any other way to get this information from here. Control p = _Draw; MDIChild mc = null; while (p != null && !(p is ReportDesigner)) { if (p is MDIChild) { mc = (MDIChild)p; } p = p.Parent; } if (p == null || mc == null || mc.SourceFile == null) { MessageBox.Show("Unable to locate DataSource Shared file. Try saving report first"); return; } string filename = Path.GetDirectoryName(mc.SourceFile) + Path.DirectorySeparatorChar + dataSourceReference; if (!DesignerUtility.GetSharedConnectionInfo((ReportDesigner)p, filename, out dataProvider, out connection)) { return; } } else { XmlNode cpNode = DesignXmlDraw.FindNextInHierarchy(datasource, "ConnectionProperties", "ConnectString"); connection = cpNode == null ? "" : cpNode.InnerText; XmlNode datap = DesignXmlDraw.FindNextInHierarchy(datasource, "ConnectionProperties", "DataProvider"); dataProvider = datap == null ? "" : datap.InnerText; } // Populate the data table DesignerUtility.GetSqlData(dataProvider, connection, _dsv.CommandText, null, _DataTable); } catch (Exception ex) { MessageBox.Show(ex.Message, "Load Failed"); } }