web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

A column named 'A' already belongs to this DataTable:

(0) ShareShare
ReportReport
Posted on by 390

Hi:
I am using queryServiceMetaData to execute client to get data. I get the following error message.
Error Message: "Error:A column named 'PrimaryContactFax' already belongs to this DataTable."
Appreciate any hint or assistance.
We run AX2012 R2.
 
The following is the code sample.

try
{
DataSet dataSet;
Paging paging = new PositionBasedPaging() { StartingPosition = 1, NumberOfRecordsToFetch = 10 };
 
 
QueryServiceClient client = new QueryServiceClient();
AxMetadataServiceClient metadataClient = new AxMetadataServiceClient();
 
// create query object for QueryService
AOTQueryServiceRef.QueryMetadata queryServiceMetaData = new AOTQueryServiceRef.QueryMetadata();
 
// Create the query object for metadata
AOTMetaDataQueryServiceRef.QueryMetadata queryMetadata = new AOTMetaDataQueryServiceRef.QueryMetadata();
 
// Get the query from the AOT using the metadata service.
queryMetadata = metadataClient.GetQueryMetadataByName(new[] { "DirPartyContacts" })[0];
 
using (MemoryStream memoryStream = new MemoryStream())
{
DataContractSerializer mdsSerializer = new
DataContractSerializer(typeof(AOTMetaDataQueryServiceRef.QueryMetadata));
DataContractSerializer qsSerializer = new
DataContractSerializer(typeof(AOTQueryServiceRef.QueryMetadata));
mdsSerializer.WriteObject(memoryStream, queryMetadata);
memoryStream.Seek(0, SeekOrigin.Begin);
queryServiceMetaData =
(AOTQueryServiceRef.QueryMetadata)qsSerializer.ReadObject(memoryStream);
 
}
//Call the query service with the query retrieved from the metadata service.


// Exception is thrown >>>> Next Line
dataSet = client.ExecuteQuery(queryServiceMetaData, ref paging);
 
DataTable contactPerson = new DataTable();
contactPerson = dataSet.Tables["ContactPerson"];
 
// Loop through the TestEmployee table and display the results.
if (contactPerson != null && contactPerson.Rows.Count > 0)
{
foreach (DataRow row in contactPerson.Rows)
{
//Console.WriteLine(row["AccountNum"].ToString() +
// "\t" + row["CustGroup"].ToString() + "\t" +
// row["ValidFrom"].ToString() + "\t" +
// row["ValidTo"].ToString());
resultStr = resultStr + string.Format("");
}
}
}
catch (Exception exp)
{
resultStr = resultStr + string.Format("Error:{0}", exp.Message);
}

*This post is locked for comments

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 44

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans