• But I have to insert in sql table only...

    I am getting error in my code below:

    Public Sub Main()

    Dim iErrorCode As Integer = _

    Convert.ToInt32(Dts.Variables("ErrorCode").Value)

    Dim sErrorDescription As String = _

    Dts.Variables("ErrorDescription").Value.ToString

    Dim sSourceName As String = _

    Dts.Variables("SourceName").Value.ToString

    Dim sSubComponent As String = _

    "OnError Event Handler"

    'Dim sMsg As String = "Source: " & sSourceName & vbCrLf & _

    ' "Error Code: " & iErrorCode.ToString & _

    ' vbCrLf & _

    ' "Error Description: " & _

    ' sErrorDescription

    'MsgBox(sMsg, , sSubComponent)

    Dim myConnection As SqlConnection

    Dim myCommand As SqlCommand

    myConnection = New SqlConnection("server = localhost ;uid = sa; pwd = 123; database = eCareProDB")

    myConnection.Open()

    myCommand = New SqlCommand("INSERT INTO DATALOAD_ERROR_LOG(EL_ErrorCode,EL_ErrorDescription) VALUES (" + Dts.Variables(iErrorCode).Value + "," + Dts.Variables(sErrorDescription).Value + ")", myConnection)

    myCommand.ExecuteNonQuery()

    myConnection.Close()

    'MsgBox(myConnection, MsgBoxStyle.Exclamation)

    Dts.TaskResult = ScriptResults.Success

    End Sub

    Error:

    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

    at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/