Using ADO.Net to Read and Update an External Table

shrekut
Member Posts: 27
I am trying to read and update a table in an external SQL Server. I am able to read the data ok, but I have not been able to figure out how to update the record I read from that table. I am including the Code Example I'm using to read. The statement to update the record is also included. Can someone please help me with an example of code that will execute the update statement?
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. } }
0
Comments
-
I think you're missing:
SQLConnection.Execute(SQLString);
befor SQLConnection.Close;
Tino Ruijs
Microsoft Dynamics NAV specialist0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions