'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsGrapeCity.Documents.Word '' This example shows how to deal with the 'data source with this name already exists' error.PublicClassDataTplFixDuplicateDataSource'' Code demonstrating the problem:PrivateFunctionProblem() AsGcWordDocumentUsing oceans = File.OpenRead(Path.Combine("Resources", "data", "oceans.json")), oceans1 = File.OpenRead(Path.Combine("Resources", "data", "oceans.json"))Dim doc = NewGcWordDocument() doc.DataTemplate.DataSources.Add("ds", oceans)'' Incorrect: data source with the name "ds" already exists, so this will throw: doc.DataTemplate.DataSources.Add("ds", oceans1)Return docEndUsingEndFunction '' Code demonstrating the fix:PrivateFunctionFix() AsGcWordDocumentUsing oceans = File.OpenRead(Path.Combine("Resources", "data", "oceans.json")), oceans1 = File.OpenRead(Path.Combine("Resources", "data", "oceans.json"))Dim doc = NewGcWordDocument() doc.DataTemplate.DataSources.Add("ds", oceans)'' Correct: give each data source a unique name: doc.DataTemplate.DataSources.Add("ds1", oceans1)Return docEndUsingEndFunction FunctionCreateDocx() AsGcWordDocumentDim doc AsGcWordDocumentTry'' This fails: doc = Problem()Catch ex As Exception'' This works: doc = Fix()'' Insert a brief explanation of the problem and the fix into the generated document: doc.Body.Paragraphs.Insert($"The error ""{ex.Message}"" occurred because the code tried to add two data sources with the same name. " +$"The fix is to use a unique name for each data source added to the GcWordDocument.DataTemplate.DataSources collection.", doc.Styles(BuiltInStyleId.BlockText),InsertLocation.Start)EndTryReturn docEndFunctionEndClass