How do I connect to an Excel spread sheet using a Script Component?
How do I connect to an Excel spread sheet using a Script Component?Mr Shaw
March 24th, 2011 6:59pm

It would not be different than just using the OLEDB Jet from within say a VB app. How about this example: http://vb.net-informations.com/excel-2007/vb.net_excel_oledb.htm ? The same code can be incorporated inside the Script Task, you merely need to reference the proper components. Besides, I am wondering why a DFT is not used to connect using the Excel Source?Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2011 7:10pm

It would not be different than just using the OLEDB Jet from within say a VB app. How about this example: http://vb.net-informations.com/excel-2007/vb.net_excel_oledb.htm ? The same code can be incorporated inside the Script Task, you merely need to reference the proper components. Besides, I am wondering why a DFT is not used to connect using the Excel Source? Arthur My Blog Do I need: DataGridView1.DataSource = DtSet.Tables(0)Mr Shaw
March 24th, 2011 7:41pm

You do not need because you are processing the data in a not visual way. Besides, you did not answer my question. I have a feeling you are on the wrong path concept-wise.Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2011 7:55pm

I can workout how to output the data.Mr Shaw
March 24th, 2011 8:19pm

The table mapping is confusing me: TableMappings.Add() Mr Shaw
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2011 8:21pm

If have no idea what I am doing. Here is my code: Imports System Imports System.Data Imports System.Math Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper Imports Microsoft.SqlServer.Dts.Runtime.Wrapper Imports System.Data.OleDb Imports System.Xml Public Class ScriptMain Private connMgr As IDTSConnectionManager90 Private cnnXls As OleDb.OleDbConnection Private tablesInFile As DataTable Dim DtSet As System.Data.DataSet Public Overrides Sub PreExecute() Dim strXLS As String = Me.Connections.excelConn.ConnectionString() Dim MyCommand As System.Data.OleDb.OleDbDataAdapter MyCommand = New System.Data.OleDb.OleDbDataAdapter _ ( "select * from [Sheet1$]", strXLS) MyCommand.TableMappings.Add( "ShopName", "ShopName") DtSet = New System.Data.DataSet MyCommand.Fill(DtSet) cnnXls = New OleDb.OleDbConnection(strXLS) cnnXls.Open() tablesInFile = cnnXls.GetSchema( "Tables") End Sub Public Overrides Sub CreateNewOutputRows() Dim rows As DataRow For Each rows In DtSet.Tables Me.myOutPutBuffer.AddRow() Me.myOutPutBuffer.HotelName = rows.Table.Columns(1).ToString() Next End Sub Public Overrides Sub ReleaseConnections() cnnXls.Close() End Sub End Class Mr Shaw Inherits UserComponent '>> ADDEDD
March 24th, 2011 8:29pm

My code give me an error reading: Unable to cast object of type 'System.Data.DataTable' to type 'System.Data.DataRow'.Mr Shaw
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2011 8:30pm

To just load an Excel spreadsheet, why do you need a script task? Arthur My Blog
March 24th, 2011 8:39pm

It is hard to read what you posted but on the surface it looks like the issue is with this statement: For Each rows In DtSet.Tables in needs to be For Each rows In DtSet.Tables<strong>.Rows</strong> Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2011 8:47pm

Thanks for the help.. I am not a programmer... so I am not sure what you mean by <strong>Mr Shaw
March 24th, 2011 10:48pm

Some HTML was applied, now corrected For Each rows In DtSet.Tables.RowsArthur My Blog
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2011 11:08pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics