Sign In Help
Schneider Electric
HelpSign In
Schneider Electric Exchange
  • Home
  • Collaborate
  • Develop
  • Shop
Home Collaborate Develop Shop Log in or Register Help

Invite a Co-worker

Send a co-worker an invite to the Exchange portal.Just enter their email address and we’ll connect them to register. After joining, they will belong to the same company.
You have entered an invalid email address. Please re-enter the email address.
This co-worker has already been invited to the Exchange portal. Please invite another co-worker.
Please enter email address
Send Invite Cancel

Invitation Sent

Your invitation was sent.Thanks for sharing Exchange with your co-worker.
Send New Invite Close
  • Home
  • Collaborate
  • Exchange Community
  • :
  • SCADA & Telemetry Solutions
  • :
  • Geo SCADA Expert Forum
  • :
  • [Imported] [Solved] Importing data into a Data Table from an Excel file
Community Menu
  • Forums
    • By Topic
        • EcoStruxure IT
          • EcoStruxure IT forum
        • Industrial Automation
          • Industry Automation and Control Forum
          • Alliance System Integrators Forum
          • Machine Solutions in the Digital Transformation
          • EcoStruxure Automation Expert / IEC 61499 Forum
          • Industrial Edge Computing Forum
          • Level and Pressure Instrumentation Forum
          • Modicon User Group
          • PLC Club Indonesia
          • SEE Automation Club Forum
          • Fabrika ve Makina Otomasyonu Çözümleri
          • Форум по промышленной автоматизации СНГ
        • SCADA & Telemetry Solutions
          • Geo SCADA Expert Forum
          • SCADA and Telemetry Devices Forum
        • Power Distribution IEC
          • Power Distribution and Digital
          • Power Standards & Regulations
          • Paneelbouw & Energie Distributie
          • Eldistribution & Fastighetsautomation
        • Power Distribution Softwares
          • EcoStruxure Power Design Forum
          • SEE Electrical Building+ Forum
          • LayoutFAST User Group Forum
        • Wireless Information Network Solutions
          • Instrument Area Network
          • Remote Monitoring
          • Tank Level Monitoring
          • Remote Data Collection
        • Solutions for your Business
          • Solutions for Food & Beverage Forum
          • Solutions for Healthcare Forum
    • By Segment
        • Food & Beverage
          • Solutions for Food & Beverage Forum
        • Healthcare
          • Solutions for Healthcare Forum
      • EcoStruxure IT
        • EcoStruxure IT forum
      • Industrial Automation
        • Industry Automation and Control Forum
        • Alliance System Integrators Forum
        • Machine Solutions in the Digital Transformation
        • EcoStruxure Automation Expert / IEC 61499 Forum
        • Industrial Edge Computing Forum
        • Level and Pressure Instrumentation Forum
        • Modicon User Group
        • PLC Club Indonesia
        • SEE Automation Club Forum
        • Fabrika ve Makina Otomasyonu Çözümleri
        • Форум по промышленной автоматизации СНГ
      • SCADA & Telemetry Solutions
        • Geo SCADA Expert Forum
        • SCADA and Telemetry Devices Forum
      • Power Distribution IEC
        • Power Distribution and Digital
        • Power Standards & Regulations
        • Paneelbouw & Energie Distributie
        • Eldistribution & Fastighetsautomation
      • Power Distribution Softwares
        • EcoStruxure Power Design Forum
        • SEE Electrical Building+ Forum
        • LayoutFAST User Group Forum
      • Wireless Information Network Solutions
        • Instrument Area Network
        • Remote Monitoring
        • Tank Level Monitoring
        • Remote Data Collection
      • Solutions for your Business
        • Solutions for Food & Beverage Forum
        • Solutions for Healthcare Forum
      • Food & Beverage
        • Solutions for Food & Beverage Forum
      • Healthcare
        • Solutions for Healthcare Forum
  • Blogs
    • By Topic
        • Industrial Automation
          • Industrial Edge Computing Blog
          • Industry 4.0 Blog
          • Industrie du Futur France
        • SCADA & Telemetry Solutions
          • SCADA and Telemetry Blog
        • Power Distribution IEC
          • Power Events & Webinars
          • Power Foundations Blog
        • Power Distribution NEMA
          • NEMA Power Foundations Blog
        • Power Distribution Softwares
          • EcoStruxure Power Design Blog
          • SEE Electrical Building+ Blog
        • Solutions for your Business
          • Solutions for Food & Beverage Blog
          • Solutions for Healthcare Blog
          • Solutions for Retail Blog
        • Community experts & publishers
          • Publishers Community
    • By Segment
        • Food & Beverage
          • Solutions for Food & Beverage Blog
        • Healthcare
          • Solutions for Healthcare Blog
        • Retail
          • Solutions for Retail Blog
      • Industrial Automation
        • Industrial Edge Computing Blog
        • Industry 4.0 Blog
        • Industrie du Futur France
      • SCADA & Telemetry Solutions
        • SCADA and Telemetry Blog
      • Power Distribution IEC
        • Power Events & Webinars
        • Power Foundations Blog
      • Power Distribution NEMA
        • NEMA Power Foundations Blog
      • Power Distribution Softwares
        • EcoStruxure Power Design Blog
        • SEE Electrical Building+ Blog
      • Solutions for your Business
        • Solutions for Food & Beverage Blog
        • Solutions for Healthcare Blog
        • Solutions for Retail Blog
      • Community experts & publishers
        • Publishers Community
      • Food & Beverage
        • Solutions for Food & Beverage Blog
      • Healthcare
        • Solutions for Healthcare Blog
      • Retail
        • Solutions for Retail Blog
  • Ideas
        • Industrial Automation
          • Modicon Ideas & new features
        • SCADA & Telemetry Solutions
          • Geo SCADA Expert Ideas
          • SCADA and Telemetry Devices Ideas
  • Knowledge Center
    • Building Automation Knowledge Base
    • Industrial Automation Knowledge Base
    • Industrial Automation How-to videos
    • SCADA & Telemetry Solutions Knowledge Base
    • Digital E-books
    • Success Stories Corner
    • Power Talks
  • Events & Webinars
    • Innovation Talks
    • Innovation Summit
    • Let's Exchange Series
    • Technology Partners
  • Support
    • Ask Exchange
    • Leaderboard
    • Our Community Guidelines
    • Community User Guide
    • How-To & Best Practices
    • More
Join Now
How can we help?
cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
51317members
Join Now
245520posts
Join Now

[Imported] [Solved] Importing data into a Data Table from an Excel file

Options
  • Subscribe to RSS Feed
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Mute
  • Printer Friendly Page
Back to Geo SCADA Expert Forum
sbeadle
Sisko sbeadle Sisko
Sisko
‎2019-10-26 02:42 AM
0 Likes
0
524
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
‎2019-10-26 02:42 AM

[Imported] [Solved] Importing data into a Data Table from an Excel file

>>Message imported from previous forum - Category:Scripts and Tips<<
User: mchartrand, originally posted: 2018-10-19 18:03:08 Id:153
This is a re-posting from the obsoleted (October 2018) "Schneider Electric Telemetry & SCADA" forum.

-------------------------------

**_hardin4019:
[Solved] See code below for working version. Note its a good bit longer than some of the other posts and includes enough comments so people can figure it out and use it again.
I need a little help understand what I'm doing wrong.
Client wants to import a list of names, addresses, phone numbers, etc from an excel file stored in a mapped network drive or locally on the server. They want that list to appear on a mimic in CS.
I have seen examples of using ST to fill in a Data Table, but I'm not having any luck with getting that ST linked to my Excel file and the correct fields in the Excel. The Excel file for now has 3 columns: Name, Address, Phone. My Data Table has the same 3 columns. The updating of the Data table doesn't need to be automated, but would be nice if at least once a day it updated on its own. From there, I am assuming a simple Query of that Data Table can display the info in a list on a mimic._**

_Sub InsertData()
Dim EmptyDB, iRowNo As Integer
Dim Name, PhoneNumber, Address As String
'All of the data being inserted is in Sheet1
With Sheets("Sheet1")
Set ado = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
EmptyDB = 1
'Skip the header row with header info
iRowNo = 2
'Put in the DSN name, Username, Password below
ado.Open "DSN=ClearSCADA", "username", "password"
'Show message box if connected to DB.
'If ado.State = 1 Then
' MsgBox "Connected"
'End If
'Delete all of the data in the table if the EmptyDB equals 1
If EmptyDB = 1 Then
ado.Execute "DELETE FROM PhoneList"
End If
'Loop until empty row
Do Until .Cells(iRowNo, 1) = "" And .Cells(iRowNo, 2) = "" And .Cells(iRowNo, 3) = ""
sName = .Cells(iRowNo, 1)
sPhoneNumber = .Cells(iRowNo, 2)
sAddress = .Cells(iRowNo, 3)
'Build the query
queryText = "INSERT INTO PhoneList (Name, PhoneNumber, Address) VALUES ('" & sName & "', '" & sPhoneNumber & "', '" & sAddress & "')"
'Execute the query
ado.Execute queryText
'Increment iRowNo and repeat until empty row
iRowNo = iRowNo + 1
Loop
'Close DB connection and message done
ado.Close
Set ado = Nothing
MsgBox "Done"
End With
End Sub_

-------------------------------

bevanweiss:
This *might* be possible using a linked table...
There is an ODBC driver for Excel workbooks.

Failing that, you could create a Data Grid that allows easy copy/paste from Excel directly into it. Then display the Data Grid on the mimic (via an embedded query).

I'll check on the linked table idea when I get into the office..

_________

AWoodland:
I don't believe Excel will work, the Windows permissions will probably block ClearSCADA creating the ODBC connection as its a file rather than a service like MSSQL.

One way could be some simple VB running as a user under Windows Task Scheduler, bit of VBS to read Excel via COM and push it into ClearSCADA via ODBC or COM

__________________

du5tin:
We managed to do this in Excel using the ADODB object to create an ODBC connection to ClearSCADA. The VBA code followed this general form:

_Sub InsertData
Set ado = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
ado.Open "DSN=ClearSCADA", username, password
For i = 1 To rowcount
queryText = Build your insert query with data from spreadsheet rows here
ado.Execute queryText
Next
MsgBox "Done"
End Sub_

Notes:

-Your DSN using the ClearSCADA must be configured in the 32-bit ODBC Control Panel. User or System tab likely won't matter, we used the system tab so the DSN was available to multiple users.

- We had to write another bit of logic to delete everything from the datatable for future bulk loads. This script had no logic for modifying existing data. Essentially the query text was "DELETE FROM _DataTableName_".

____________________________________________

du5tin:
On reading the post again I realize that manually loading the data into ClearSCADA via Excel was not Shawn's original intent.

Bevan and Adam have good suggestions if you want to reference some network file somewhere as a bit of a 'live' data source instead.

You might be just as quick to build an interface to manage this data inside ClearSCADA without an external file. There are lots of ways an external file could break: If the client changes the file format (renames or adds a column) or the file gets renamed or deleted you might be reworking things inside ClearSCADA to get that data displayed again.

If all the name and phone number information is attached to users already in ClearSCADA you could just query ClearSCADA to display the info too. If the info changes I would expect the users in CLearSCADA to stay fairly up to date (for alarm redirections, etc.) so it should be a reliable source.

________________

**_hardin4019:
Spending a little time working through the suggestion from Dustin. Below is what I have, and I am getting an error message about "Access Denied"._**

_Sub InsertData()
Dim EmptyDB As Integer
Set ado = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
EmptyDB = 0
ado.Open "DSN=ClearSCADA", Training, 123456789123#
If ado.State = 1 Then
MsgBox "Connected"
End If
If EmptyDB = 1 Then
ado.Execute "DELETE FROM PhoneList2"
End If
queryText = "insert into PhoneList2 (Name, PhoneNumber, Address) values ('" & A$ & "', '" & B$ & "', '" & C$ & "')"
ado.Execute queryText
ado.Close
Set ado = Nothing
MsgBox "Done"
End Sub_

______________________________

du5tin:
I guess check to see if:

1. Your DSN is setup in both 32-bit and 64-bit ODBC control panels (I use the same name for both so it can be found no matter which architecture the ODBC client is)

2. Enclose your username and password in quotes (they are strings)

3. Check that you can log on using the user in ViewX (sounds silly, but sometimes the user is disabled or locked out).

__________________________________

**_I have both 32 bit and 64 bit ODBC connections setup. Using a username and password I am logging in with. I thought maybe it was happening because "logon as a service" wasn't enabled. But now after putting quotes around the username and password, I am getting the script to run, but still not seeing data in the table._**

__________

bevanweiss:
Where are you getting this error? (at which line)

I assume that it's ado.Open.
The syntax there looks a bit unusual, I guess I'm more used to putting the username and password within the ODBC / OLEDB connection string itself.

I'd generally do such development within Excel and VBA, then you can just migrate it into VBScript for ViewX/WebX pretty easily (just pulling out type definitions and a few other small items).


____________________

**_hardin4019:
I was getting "Access Denied" at row ado.Execute queryText. Now I put quotes around the username and password and I am no longer getting access denied, but nothing is being added to the table. So One step closer, but not quite there yet._**

_________________________

**_hardin4019:
[Solved] See code below for working version. Note its a good bit longer than some of the other posts and includes enough comments so people can figure it out and use it again._**

_Sub InsertData()
Dim EmptyDB, iRowNo As Integer
Dim Name, PhoneNumber, Address As String
'All of the data being inserted is in Sheet1
With Sheets("Sheet1")
Set ado = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
EmptyDB = 1
'Skip the header row with header info
iRowNo = 2
'Put in the DSN name, Username, Password below
ado.Open "DSN=ClearSCADA", "username", "password"
'Show message box if connected to DB.
'If ado.State = 1 Then
' MsgBox "Connected"
'End If
'Delete all of the data in the table if the EmptyDB equals 1
If EmptyDB = 1 Then
ado.Execute "DELETE FROM PhoneList"
End If
'Loop until empty row
Do Until .Cells(iRowNo, 1) = "" And .Cells(iRowNo, 2) = "" And .Cells(iRowNo, 3) = ""
sName = .Cells(iRowNo, 1)
sPhoneNumber = .Cells(iRowNo, 2)
sAddress = .Cells(iRowNo, 3)
'Build the query
queryText = "INSERT INTO PhoneList (Name, PhoneNumber, Address) VALUES ('" & sName & "', '" & sPhoneNumber & "', '" & sAddress & "')"
'Execute the query
ado.Execute queryText
'Increment iRowNo and repeat until empty row
iRowNo = iRowNo + 1
Loop
'Close DB connection and message done
ado.Close
Set ado = Nothing
MsgBox "Done"
End With
End Sub_

Labels
  • SCADA
Share
  • All forum topics
  • Previous Topic
  • Next Topic
Related Products
Schneider Electric
EcoStruxure™ Geo SCADA Expert
Top Experts
User Count
sbeadle
Sisko sbeadle Sisko
188
BevanWeiss
Sisko BevanWeiss
53
AdamWoodland
Lt. Commander AdamWoodland Lt. Commander
16
JChamberlain
Lieutenant JChamberlain Lieutenant
16
AndrewScott
Lieutenant AndrewScott
15
See More Top Experts
Find a Service Provider
Find a certified partner to help you address your integration, installation, maintenance and project needs.
View all Providers
Support

Have a question? Please contact us with details, and we will respond.

Contact Us
FAQ

Look through existing questions to find popular answers.

Learn More
About

Want to know more about Exchange and its possibilities?

Learn More

Full access is just steps away!

Join Exchange for FREE and get unlimited access to our global community of experts.

Connect with Peers & Experts

Discuss challenges in energy and automation with 30,000+ experts and peers.

Get Support in Our Knowledge Base

Find answers in 10,000+ support articles to help solve your product and business challenges.

Ask Questions. Give Solutions

Find peer based solutions to your questions. Provide answers for fellow community members!

Register today for FREE

Register Now

Already have an account?Log in

About Us FAQ Terms & Conditions Privacy Notice Change your cookie settings
©2020, Schneider Electric