Hello,
I have a scenario, where I need to bring all customers using ODBC connection. I successfully establish the connection and its print the all customers. Now some customers already created before in ax from external system using AIF/.net business connector approach. We create a custom field in Cust table say ExternalCustCode and use this for data validation in .net to bring those data which is not available in ax. Now how Can I query using ODBC connection to achieve same scenario to bring customers which is not available in system. In the below code where I can make validation with ODBC query to print the required customers which not exists in ax ?
// X , Main method in a class.
public server static void main(Args _args)
{
LoginProperty loginProperty;
OdbcConnection odbcConnection;
Statement statement;
ResultSet resultSet;
str sql, criteria, axsql;
SqlStatementExecutePermission perm;
CustTable custTable;
;
// Set the information on the ODBC.
loginProperty = new LoginProperty();
loginProperty.setDSN("systemrote");
//Create a connection to external database.
odbcConnection = new OdbcConnection(loginProperty);
if (odbcConnection)
{
/* sql = "select *from customermaster WHERE customercode=131"
criteria
" ORDER BY customername, customerphone ASC ;";*/
sql = "select *from customermaster";
//Assert permission for executing the sql string.
perm = new SqlStatementExecutePermission(sql);
perm.assert();
//Prepare the sql statement.
statement = odbcConnection.createStatement();
resultSet = statement.executeQuery(sql);
//Cause the sql statement to run,
//then loop through each row in the result.
// select firstOnly custTable where custTable.ExternalCustCode != resultSet.getString(1) ;
while (resultSet.next())
{
//It is not possible to get field 3 and then 1.
//Always get fields in numerical order, such as 1 then 2 the 3 etc.
print resultSet.getString(1);
// print resultSet.getString(2);
// print resultSet.getString(3);
// print resultSet.getString(4);
// print resultSet.getString(5);
// print resultSet.getString(6);
// print resultSet.getString(7);
// print resultSet.getString(8);
print resultSet.getString(9);
pause;
//}
// print resultSet.getString(4);
}
//Close the connection.
resultSet.close();
statement.close();
}
else
{
error("Failed to log on to the database through ODBC.");
}
}