Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically import an Excel file in SQL using DTS

Status
Not open for further replies.

Malchik

Programmer
Dec 8, 2001
148
CA
Hi,

I created a DTS in SQL that gets an Excel file and imports it in a table. The file source path and name may change, since multiple users will upload it through an Intranet site. I searched a way to dynamically set the source and filename using a Gloabal variable in the DTS and sevral different coding in ASP.NET. Finally I went for the simple, I removed the global variable and use only .NET

Here is the code: (you have to add the Microsoft DTS Package 2 COM as reference)

Dim pkg As New DTS.Package2

Call pkg.LoadFromSQLServer(sServer, sUserName, sPassword, DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, , , , _
"ImportEmployeeStats")
pkg.Connections.Item("Connection 1").DataSource = sPath & sFileName

Call pkg.Execute()
pkg.UnInitialize()
pkg = Nothing

In this example I used an SQL Login and Password. If you do the same, make sure to set the DTS with the right credential.


Hope that will help someone else...

Mal'chik [bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top