Read data from ExternalDataSource

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Sep 27, 2023
Company:

Hi Experts,
 
i want to get data from external data source ExternalDataSources.XXXX.Tables.XXXX;

 how can i get all table data and iterate it,

 i tried like below but gives me error


 For Each DataRow In ExternalDataSources.XXX.Tables.XXXX Do

 EndDo;

 
#2
People who like this:0Yes/0No
Administrator
Rating: 28
Joined: Oct 3, 2019
Company:

Hello Selim!

None of the experts have answered you, so let me try to help you :)

For first - could you provide a more complete code?

And in general, it is better to work with external data sources using queries:



Code
   Query = New Query;
   Query.Text = 
      "SELECT
      |   dbo_CURRENCIES.CODE AS CODE,
      |   dbo_CURRENCIES.NAME AS NAME,
      |   dbo_CURRENCIES.STATUS AS STATUS,
      |   dbo_CURRENCIES.EXTCODE AS EXTCODE
      |FROM
      |   ExternalDataSource.RK_RKeeper7.Table.dbo_CURRENCIES AS dbo_CURRENCIES";
   
   QueryResult = Query.Execute();
   
   SelectionDetailRecords = QueryResult.Select();
   
   While SelectionDetailRecords.Next() Do
      // Insert selection processing SelectionDetailRecords
   EndDo;

 
#3
People who like this:0Yes/0No
Active user
Rating: 8
Joined: May 21, 2023
Company:

And how do you connect to external data source?

 
#4
People who like this:0Yes/0No
Administrator
Rating: 28
Joined: Oct 3, 2019
Company:

Hello Peter!

How to connect to an external source - this is material for a small article... :-)

I have prepared several screenshots. I hope it will be clear to you how to connect. If you have any questions - ask!

 
#5
People who like this:0Yes/0No
Administrator
Rating: 28
Joined: Oct 3, 2019
Company:

First we add an external source in the Designer:

Download Pic_1.png (15.21 KB)
Download Pic_2.png (26.78 KB)
Download Pic_3.png (29.83 KB)
Download Pic_4.png (13.43 KB)
Download Pic_5.png (24.88 KB)
 
#6
People who like this:0Yes/0No
Administrator
Rating: 28
Joined: Oct 3, 2019
Company:

Select the tables whose data we want to work with. Also pay attention to screenshot 7 - it is necessary that the key field is filled in!

Download Pic_6.png (21.39 KB)
Download Pic_7.png (48.27 KB)
 
#7
People who like this:0Yes/0No
Administrator
Rating: 28
Joined: Oct 3, 2019
Company:

Now we launch 1C in working mode and open the External Source there:

Download Pic_8.png (20.96 KB)
 
#8
People who like this:0Yes/0No
Administrator
Rating: 28
Joined: Oct 3, 2019
Company:

There is one nuance here - when connecting for the first time, we need to specify the login and password again. Or the easiest way is to use the connection string, which can be copied from the Designer:

Download Pic_9.png (24.59 KB)
 
#9
People who like this:0Yes/0No
Administrator
Rating: 28
Joined: Oct 3, 2019
Company:

After this, we can work with the data in the tables directly:

 
#10
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Sep 27, 2023
Company:

Thank you for your help.

İs there another way to get all data from table without Query selection like below code

For Each DataRow In ExternalDataSources.XXX.Tables.XXXX Do

EndDo;

 
#11
People who like this:0Yes/0No
Administrator
Rating: 28
Joined: Oct 3, 2019
Company:

As far as I know, the table of the external data source cannot be iterated, so this code:

Code
For Each a In ExternalDataSources.ExternalDataSource1.Tables.HumanResources_Employee Do 
   
EndDo;


won't work.

But I'll check with the developers. Thanks for the question!

 
#12
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Sep 27, 2023
Company:

Thank you for your help Sır

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.