OBJECT Codeunit 50006 ADO.Net External Table { OBJECT-PROPERTIES { Date=11/25/14; Time=[ 9:23:03 AM]; Modified=Yes; Version List=; } PROPERTIES { OnRun=BEGIN SRSetup.GET; CLEAR(SQLReader); CLEAR(SQLCommand); CLEAR(SQLConnection); SQLConnection := SQLConnection.SqlConnection('Server=' + SRSetup."SQL Server Name" + ';' + 'Database=' + SRSetup."SQL Database Name" + ';' + 'User ID=' + SRSetup."SQL Login ID" + ';' + 'Password=' + SRSetup."SQL Password" + ';'); SQLString := 'SELECT * FROM tNavisionOrders WHERE ImportStatus = ' + '''' + 'Pending' + '''' + ';'; SQLConnection.Open; SQLCommand := SQLConnection.CreateCommand(); SQLCommand.CommandText := SQLString; SQLReader := SQLCommand.ExecuteReader; SQLReader.Read(); DateStr := SQLReader.GetSqlValue(1); EVALUATE(TestDate,COPYSTR(DateStr,3,2) + '/' + COPYSTR(DateStr,1,2) + '/' + COPYSTR(DateStr,5,4)); RemoteRefNo := SQLReader.GetSqlValue(0); ImportStatus := SQLReader.GetSqlValue(46); MESSAGE( 'Reading %1 || %2 || %3',RemoteRefNo,TestDate,ImportStatus); SQLString := 'UPDATE tNavisionOrders SET ImportStatus = ' + '''' + 'Imported' + '''' + ' WHERE ImportStatus = ' + '''' + 'Pending' + '''' + ' AND OrderNo = ' + '''' + RemoteRefNo + '''' + ';'; // Need code to Update the above record (RemoteRefNo) with ImportStatus := 'Imported' SQLConnection.Close; END; } CODE { VAR SQLConnection@1000000009 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.SqlClient.SqlConnection"; SQLCommand@1000000008 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.SqlClient.SqlCommand"; SQLReader@1000000007 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.SqlClient.SqlDataReader"; SQLString@1000000005 : Text[1000]; SRSetup@1000000004 : Record 311; TestDate@1000000003 : Date; DateStr@1000000002 : Text[250]; RemoteRefNo@1000000001 : Text[250]; ImportStatus@1000000000 : Text[250]; EVENT SQLCommand@1000000008::StatementCompleted@57(sender@1000000001 : Variant;e@1000000000 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.StatementCompletedEventArgs"); BEGIN END; EVENT SQLCommand@1000000008::Disposed@58(sender@1000000001 : Variant;e@1000000000 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.EventArgs"); BEGIN END; EVENT SQLConnection@1000000009::InfoMessage@48(sender@1000000001 : Variant;e@1000000000 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.SqlClient.SqlInfoMessageEventArgs"); BEGIN END; EVENT SQLConnection@1000000009::StateChange@49(sender@1000000001 : Variant;e@1000000000 : DotNet "'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Data.StateChangeEventArgs"); BEGIN END; EVENT SQLConnection@1000000009::Disposed@50(sender@1000000001 : Variant;e@1000000000 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.EventArgs"); BEGIN END; BEGIN END. } }
Comments
Tino Ruijs
Microsoft Dynamics NAV specialist