0

vb.net 内で SQL クエリを実行できることがわかっています。以下のスクリプトはうまく機能します。

パブリック サブ メイン()

    ''mail variables

    Dim myHtmlMessage As MailMessage
    Dim mySmtpClient As SmtpClient
    Dim value As NetworkCredential


    ''sql variables
    Dim fireAgain As Boolean = True
    Dim rowsAffected As Integer
    Dim sqlConn As System.Data.SqlClient.SqlConnection
    Dim sqlComm As System.Data.SqlClient.SqlCommand




    Dim cm As ConnectionManager = Dts.Connections("cnn") ''Retrive the reference to the managed Connections

    '' Request an open connection
    sqlConn = cm.AcquireConnection(Dts.Transaction)
    Dts.Events.FireInformation(0, "", "Connection is: " + sqlConn.State.ToString(), "", 0, fireAgain)


    ''Do your work
    sqlComm = New System.Data.SqlClient.SqlCommand("select count(*) from table", sqlConn)
    rowsAffected = sqlComm.ExecuteScalar()

    ''sqlComm.ExecuteNonQuery() if you do not want to return anything 

    ''Inform SSIS you're done your work
    cm.ReleaseConnection(sqlConn)
    Dts.Events.FireInformation(0, "", rowsAffected.ToString() + " rows updated.", "", 0, fireAgain)
    'MsgBox(rowsAffected.ToString())





    myHtmlMessage = New MailMessage("email", "email", "This is a testing from  VB script Task", rowsAffected.ToString)
    mySmtpClient = New SmtpClient("send.company.net")
    mySmtpClient.Port = 585
    value = New NetworkCredential("email", "pwd") ''this is the line added


    mySmtpClient.Credentials = value
    mySmtpClient.EnableSsl = True
    mySmtpClient.Send(myHtmlMessage)
    Dts.TaskResult = ScriptResults.Success


End Sub


私の質問は、Vb.net SSIS スクリプト タスクで結果セットを返すデータ コマンドを実行したい場合はどうすればよいですか? 最初のスクリプトには、カウントを保持する rowsAffected という変数があります。しかし、2 番目のスクリプトでは、12 行を超える結果セットを取得する必要があります。ブロー スクリプトに対してどのような変更を行うことができますか? 文字列の配列を実装する必要があるようなものですか?

パブリック サブ メイン()

    ''mail variables

    Dim myHtmlMessage As MailMessage
    Dim mySmtpClient As SmtpClient
    Dim value As NetworkCredential


    ''sql variables
    Dim fireAgain As Boolean = True
    Dim rowsAffected As Integer
    Dim sqlConn As System.Data.SqlClient.SqlConnection
    Dim sqlComm As System.Data.SqlClient.SqlCommand




    Dim cm As ConnectionManager = Dts.Connections("cnn") ''Retrive the reference to the managed Connections

    '' Request an open connection
    sqlConn = cm.AcquireConnection(Dts.Transaction)
    Dts.Events.FireInformation(0, "", "Connection is: " + sqlConn.State.ToString(), "", 0, fireAgain)


    ''Do your work
    **sqlComm = New System.Data.SqlClient.SqlCommand("select n.c as [Total_Row_inserted_by this_Load],reverse(substring(reverse(n.[SourceFileName]),1,9)) Filename        from()(SELECT count(*) c, [SourceFileName]  FROM [Testing-DB].[dbo].[AE_Data]  group by [SourceFileName]", sqlConn)**
    **rowsAffected = sqlComm.ExecuteScalar()**

    ''sqlComm.ExecuteNonQuery() if you do not want to return anything 

    ''Inform SSIS you're done your work
    cm.ReleaseConnection(sqlConn)
    Dts.Events.FireInformation(0, "", rowsAffected.ToString() + " rows updated.", "", 0, fireAgain)
    'MsgBox(rowsAffected.ToString())





    myHtmlMessage = New MailMessage("email", "email", "This is a testing from  VB script Task", rowsAffected.ToString)
    mySmtpClient = New SmtpClient("send.company.net")
    mySmtpClient.Port = 585
    value = New NetworkCredential("email", "pwd") ''this is the line added


    mySmtpClient.Credentials = value
    mySmtpClient.EnableSsl = True
    mySmtpClient.Send(myHtmlMessage)
    Dts.TaskResult = ScriptResults.Success


End Sub
4

1 に答える 1