I am trying to create a SSIS package that will select all the value from a table in SQL Server to a table in Excel. The table is created on the run because it will change every time I run it. I can create the new table in the Excel sheet but I am having a lot of trouble getting the data in there.
I cannot do an openrowset query because the company I work for will not allow it. It cannot be done through the data task flow because i don't know what the headers at the start.
I have tried some script tasks but cannot figure out how to get it to the Excel sheet
Does anyone have any sample code or anything that will show me how to export from SQL Server to Excel dynamically?
Dim cn As New OleDbConnection
Dim sqlcn As New SqlConnection
Dim adapter As New OleDbDataAdapter
Dim dtset As New DataSet
Dim dt As New DataTable
Dim cmd As New OleDbCommand
Dim sqlcmd As New SqlCommand
Dim dr As DataRow
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Excel 8.0;Database=E:\sheet.xls;" + "HDR=Yes;Readonly=False;IMEX=0;"
sqlcn.ConnectionString = "Data Source=DB_NAME;Initial Catalog=Main;Integrated Security=True"
cn.Open()
sqlcn.Open()
Dim da As New SqlDataAdapter("Select * from Temp_Totals", sqlcn)
da.Fill(dt)
So far now I need to insert in to the Excel from the dt and I just am having trouble with that I think this will work I am not sure. If some one has a better idea I would love to hear it