http://reddymsbitools.blogspot.com

Tuesday, 22 February 2011

Loading the unstructured flatfiles into database??????

' Microsoft SQL Server Integration Services Script Component
' Write scripts using Microsoft Visual Basic 2008.
' ScriptMain is the entry point class of the script.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports System.IO


_
_
Public Class ScriptMain
Inherits UserComponent

Public Overrides Sub PreExecute()
MyBase.PreExecute()
'
' Add your code here for preprocessing or remove if not needed
'
End Sub

Public Overrides Sub PostExecute()
MyBase.PostExecute()
'
' Add your code here for postprocessing or remove if not needed
' You can set read/write variables here, for example:
' Me.Variables.MyIntVar = 100
'
End Sub

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Row.Col1 = QuoteSplit(1, Row.Column0, ",")
Row.Col2 = QuoteSplit(2, Row.Column0, ",")
Row.Col3 = QuoteSplit(3, Row.Column0, ",")
Row.Col4 = QuoteSplit(4, Row.Column0, ",")
Row.Col5 = QuoteSplit(5, Row.Column0, ",")
Row.Col6 = QuoteSplit(6, Row.Column0, ",")
Row.Col7 = QuoteSplit(7, Row.Column0, ",")

End Sub
Public Function QuoteSplit(ByVal token As Integer, ByVal parseString As String, ByVal ParamArray Delimiters() As String) As String
Dim Results() As String
Dim StringEncoding As New Text.ASCIIEncoding()
Using MemStream As New MemoryStream(StringEncoding.GetBytes(parseString))
Using Parser As New FileIO.TextFieldParser(MemStream)
Parser.Delimiters = Delimiters
Parser.HasFieldsEnclosedInQuotes = True
Results = Parser.ReadFields()
End Using
End Using
If Results.Length < token Then 'Protect against a request for a token that doesn't exist
Return ""
Else
Return Results(token - 1)
End If
'Return Results(token - 1)
' Return New List(Of String)(Results)
End Function

End Class

No comments:

Post a Comment