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)

Report
All responses (
Answers (