Hello Palle,
I am able to import mdb(MS Access) file data into AX Tables using ODBC Connection,but the problem
is before running my code i have to do setup the database name in Control Panel ->Administrative tools->Datasources(ODBC)->DSN. Here i have to select database name i.e., mdb file name.After this if i try to import another file which was not selected in above Control panel path ,if i run the code now AX is importing the file which is in DSN but now which i have selected dialog of my code.
My code is as follows:
static void importmdbodbc(Args _args)
{
LoginProperty LP = new LoginProperty();
OdbcConnection myConnection;
//ableName TableName;
Dialog dialog;
DialogField dialogfile;
DialogField dialogpwd;
TestImport test;
Statement myStatement;
ResultSet myResult;
str pwd,amount,recieptdate,myConnectionString;
FileName filename;
date d1;
;
dialog = new Dialog("Mdb file Upoad");
dialogfile = dialog.addField(typeId(FilenameOpen));
//ialogpwd = dialog.addField(typeId(Password));
//ialog.filenameLookupFilter(["@SYS28576",#XLSX,"@SYS28576",#XLS]);
dialog.filenameLookupTitle("Upload from Excel");
dialog.caption("Mdb Upload");
dialogfile.value(filename);
if(!dialog.run())
return;
filename = dialogfile.value();
pwd = "bcits2005";
#define.Constring("DSN=Xtreme Sample Database;DB=filename;Data Source =filename;PWD=yyy")//
//define.Constring("PWD=yyy")
//#define.Constring("DRIVER={Driver do Microsoft Access};DSN=Xtreme Sample Database1;Data Source =filename;PWD=bcits2005")
//myConnectionString=strfmt("PWD=%1",pwd);
//LP.setDSN("Xtreme Sample Database");
//LP.setDatabase("filename");
//Lp.setOther(myConnectionString);
try
{
LP.setOther(#Constring);
myConnection = new OdbcConnection(LP);
}
catch
{
info("Check username/password.");
return;
}
myStatement = myConnection.createStatement();
new SqlStatementExecutePermission("SELECT * from xxx where bImportflag = 0").assert();
myResult = myStatement.executeQuery("SELECT * from xxx");
CodeAccessPermission::revertAssert();
while (myResult.next())
{
test.CustAccount = myResult.getString(3);
recieptdate = myResult.getString(4);
//test.Filename = filename;
test.Recieptdate = str2date(recieptdate,123);//(myResult.getString(4),123);
amount = myResult.getString(5);
test.Amount = any2real(strdel(amount,1,1));//any2real(myResult.getString(5));
test.insert();
//print myResult.getString(3);
//info(strfmt("%1",myResult.getString(1)));
}
}