load data in table
I have created on SSIS package where I used Script task for retrieving data from some source and I have retrieved data in one .net datatable using .net code. now I want to load that data into a database table.
Sometimes it happens that I am not aware of the number of columns source is going to return so can we have any provision by which we can directly copy .net datatable code with schema of table in database table.
July 13th, 2012 3:32am
Generally, SELECT * INTO #tmp FROM tbl WHERE....Best Regards,Uri Dimant SQL Server MVP,http://sqlblog.com/blogs/uri_dimant/
Blog : MS SQL Development and Optimization
Blog : Large
scale of database and cleansing
Free Windows Admin Tool Kit Click here and download it now
July 13th, 2012 3:45am
I would iterate over your .net datatable, get the columns and create a dynamic CREATE TABLE statement.MCTS, MCITP - Please mark posts as answered where appropriate.
July 13th, 2012 3:58am
First you have to find the name of the columns, and that depend on your access to your source
i.e: for excel use .NET something like .....
Dim columnsInTable As DataTable
Dim columnInTable As DataRow
Dim columnRestrictions(3) As String '= (Nullable, Nullable, CurrentSheet , nullable )
columnRestrictions(2) = CurrentSheet ' this will restrict the columns list to the current sheet only
Dim strCurrentColumnFieldSourceFieldNames As String = ""
columnsInTable = oledbExcelConnection.GetSchema("COLUMNS", columnRestrictions)
Dim i As Integer = columnsInTable.Rows.Count
Dim strTemp As String = ""
For Each columnInTable In columnsInTable.Rows
'If columnInTable.Item("TABLE_NAME").ToString = CurrentSheet Then
strTemp = columnInTable.Item("COLUMN_NAME").ToString & ","
If InStr(strColumnFieldSourceFieldNames, strTemp) Then
'strCurrentColumnFieldSourceFieldNames = strCurrentColumnFieldSourceFieldNames & strTemp
strCurrentColumnFieldSourceFieldNames &= strTemp
'MsgBox(currentColumn)
End If
Next
i.e: for SQL use :SQL TASK:
SET NOCOUNT ON
DECLARE @tblName nVarChar(100)
SET @tblName = ?
SET @tblName = LTrim(RTrim(@tblName))
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE '[' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']'= @tblName
.
.
.
.
NOTE THAT ALL THE CODES MUST CHANGESincerely Nik -- Please kindly mark the post(s) that answered your question and/or vote for the post(s).
Free Windows Admin Tool Kit Click here and download it now
July 13th, 2012 9:22am
Thanks all for your reply....
How to copy datatable records to excel ?
July 16th, 2012 3:05am
It depends. If you created the table already, you can use a simple dataflow task to copy the data from the source to the destination.MCTS, MCITP - Please mark posts as answered where appropriate.
Free Windows Admin Tool Kit Click here and download it now
July 16th, 2012 8:48am