Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hello all,

I have developed package in sql server 2008 r2. I want to convert the data using script block.but i got the error that was the first and last records is not inserted and it tries to insert null that violates integrity contraint..below is my code in vb script..

<microsoft.sqlserver.dts.pipeline.ssisscriptcomponententrypointattribute()> _
<clscompliant(false)> _
Public Class ScriptMain
Inherits UserComponent
Dim i As Integer = 0

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)
'
' Add your code here
'

While Row.NextRow()

i = i + 1
With Output0Buffer
.OrderHeaderID = i
.CustomerNumber = Row.CUSTNO
.OrderNumber = Row.ORDER
.TermsCode = Row.TRMSCD
.TermsDescription = Row.TRMDSC
.TotalLines = Row.TOTLNS
.TotalDollars = Row.TOTDOL
.ComCls = Row.COMCLS
.DropShip = Row.DRPSHP
.DropshipPurchaseOrder = Row.DSPONO
.InvoiceNumber = Row.INVNO
.LstSeq = Row.LSTSEQ
.OrderType = Row.ORDTYP
.PONumber = Row.PONUMB
.ProgramCode = Row.PROGCD
.ProgramDeal = Row.PROGDL
.ProgramName = Row.PRGNAM
.PRONumber = Row.PRONUM
.ReceivedVia = Row.RCVVIA
.StatusMessage = Row.STAMSG
.TermsDescription = Row.TRMDES
.TermsDiscount = Row.TRMDSC
.TruckName = Row.TRKNAM

If IsDate(Row.SHPDAT) Then
.ShipDate = Row.SHPDAT
End If

If IsDate(Row.ORDDAT) Then
.OrderDate = Row.ORDDAT
End If

If IsDate(Row.INVDAT) Then
.InvoiceDate = Row.INVDAT
End If

If IsDate(Row.DATING) Then
.Dating = Row.DATING
End If

If Not Row.INVDAT_IsNull Then
.AddRow()
Else
Exit Sub
End If
End With

End While
End Sub

Public Overrides Sub CreateNewOutputRows()

Output0Buffer.AddRow()

End Sub
End Class

Currently i am trying to insert 10 rows but it gives error.
Please guide me.

Thanks in advance.
Ritesh
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900